此功能要实现 管线与构筑物(墙、梁、楼板、天花板、屋顶)交点开洞,并且要把管线与洞口关联起来。
首先是开洞,以墙为例
大致思路:1、得到墙体的水平面
2、得到管线与墙面相交的两点,并计算出中点
3、在中点创建洞口族并执行剪切
private void OpeningHole(Element wall,Curve line)
{
//得到墙的面
List<Face> lstFace = Get_ElementFace(wall);
//得到管线与墙的交点
List<XYZ> lstIntersection = Get_Intersection(line, lstFace);
//计算中心点
XYZ ptIntersection = (lstIntersection[0] + lstIntersection[1]) / 2
Transaction trans = new Transaction(doc, "opening");
trans.Start();
try
{
//创建洞口
FamilyInstance instance = doc.Create.NewFamilyInstance(ptIntersection, fs, StructuralType.NonStructural);
//执行剪切
InstanceVoidCutUtils.AddInstanceVoidCut(doc, wall, instance);
trans.Commit();
}
catch
{
trans.RollBack();
}
}
/// <summary>
/// 找到宿主的面
/// </summary>
public static List<Face> Get_ElementFace(Element element)
{
Options opt = new Options();
opt.ComputeReferences = true;
opt.DetailLevel = ViewDetailLevel.Fine;
GeometryElement geometryElement = element.get_Geometry(opt);
Face normalFace = null;
List<Face> lstFace = new List<Face>();
foreach (var go in geometryElement)
{
if(go is Solid)
{
Solid solid = go as Solid;
if (solid != null && solid.Faces.Size > 0)
{
foreach (Face face in solid.Faces)
{
PlanarFace planarFace = face as PlanarFace;
if (planarFace != null)
{
lstFace.Add(face);
}
}
}
}
else if(go is GeometryInstance)
{
GeometryInstance gins = goas GeometryInstance;
if (gins != null)
{
GeometryElement ge = gins.GetInstanceGeometry();
foreach (GeometryObject go in ge)
{
C#实现管线与洞口关联功能

最低0.47元/天 解锁文章
1393





