Revit使用空心拉伸剪切实体

使用空心拉伸剪切一个带有实心拉伸的族,可用如下方法,参数传入此族实例。
也可创建空心融合等进行剪切。
代码如下:

public void EditAndLoadFamilyToDocument(FamilyInstance instance)
{
    // 编辑族,拿到族文档 
    Document familyDoc = _doc.EditFamily(instance.Symbol.Family);
    Transaction ts = new Transaction(familyDoc, "edit");
    ts.Start();
    //创建空心拉伸
    double len = 1;
    XYZ p1 = new XYZ(-len, -len, 0);
    XYZ p2 = new XYZ(len, -len, 0);
    XYZ p3 = new XYZ(len, len, 0);
    XYZ p4 = new XYZ(-len, len, 0);
    Line l1 = Line.CreateBound(p1, p2);
    Line l2 = Line.CreateBound(p2, p3);
    Line l3 = Line.CreateBound(p3, p4);
    Line l4 = Line.CreateBound(p4, p1);
    CurveArrArray ary = new CurveArrArray();
    CurveArray arry = new CurveArray();
    arry.Append(l1);
    arry.Append(l2);
    arry.Append(l3);
    arry.Append(l4);
    ary.Append(arry);
    Plane p1 = familyDoc.Application.Create.NewPlane(XYZ.BasisZ, XYZ.Zero);
    //参数IsSolid代表创建的是空心
    Extrusion extrusion = familyDoc.FamilyCreate.NewExtrusion(false, ary, SketchPlane.Create(familyDoc, p1), 2);
    //过滤拉伸
    FilteredElementCollector extCollector = new FilteredElementCollector(familyDoc);
    extCollector = extCollector.WherePasses(new ElementClassFilter(typeof(Extrusion)));
    //连接拉伸(连接空心即为剪切)
    CombinableElementArray cea = new CombinableElementArray();
    foreach (Extrusion item in sweeps)
    {
        cea.Append(item);
    }
    familyDoc.CombineElements(cea);
    ts.Commit();
    // 将这些修改重新载入到工程文档中 
    Family loadedFamily = familyDoc.LoadFamily(_doc, new projectFamLoadOption());
}

重载族文档

public class projectFamLoadOption : IFamilyLoadOptions
{
    bool IFamilyLoadOptions.OnFamilyFound(bool familyInUse, out bool overwriteParameterValues)
    {
        overwriteParameterValues = true;
        return true;
    }
    bool IFamilyLoadOptions.OnSharedFamilyFound(Family sharedFamily, bool familyInUse, out FamilySource source, out bool overwriteParameterValues)
    {
        source = FamilySource.Project;
        overwriteParameterValues = true;
        return true;
    }
}

你可能感兴趣的:(Revit二次开发)