Revit如何判断两个Element是否相交

在Revit中,构件类型的基类是Element的都有这样一个接口

 public BoundingBoxXYZ get_BoundingBox(View A_0);

获取的就是某个视口下的外包。一般来说使用的时候都选择当前活动视口,如果有其他需要另当别论。

但是BoundingBoxXYZ这个类中并不存在判断和另一个外包是否相交的接口,但是我发现Outline这个类型有

public bool Contains(XYZ point, double tolerance);
public bool ContainsOtherOutline(Outline otherOutline, double tolerance);

public bool Intersects(Outline outline, double tolerance);

这些接口都是可以判断和另一个外包关系的。

现在就是要通过BoundingBoxXYZ构建这个Outline

            XYZ minXYZ = BoxXYZ.Min;
            XYZ maxXYZ = BoxXYZ.Max;
            return  new Outline(minXYZ , maxXYZ );

构建两个Outline,就可以粗略判断两个元素外包关系了,如果两个Outline都不相交,那说明肯定不相交。

但是,Outline相交却不一定说明元素真实相交,原因是通过Outline获得的是矩形外包,不代表元素真实轮廓;

欢迎加入我的QQ群,一起探讨Revit二次开发技术!

QQ群:631436766

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好,这是一个IT类问题。 要找到和楼板相交的梁,可以使用Revit API中的Intersection方法。具体步骤如下: 1. 获取所有的梁和楼板元素。 2. 遍历所有的梁元素,对于每一个梁元素,使用Intersection方法判断是否和任何一个楼板元素相交。 3. 如果梁和楼板相交,则将其记录下来或者执行其他相应的操作。 以下是C#代码示例,仅供参考: ``` // 获取所有的梁和楼板元素 FilteredElementCollector beamCollector = new FilteredElementCollector(doc); ElementCategoryFilter beamCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming); List<Element> beams = beamCollector.WherePasses(beamCategoryFilter).WhereElementIsNotElementType().ToList(); FilteredElementCollector floorCollector = new FilteredElementCollector(doc); ElementCategoryFilter floorCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Floors); List<Element> floors = floorCollector.WherePasses(floorCategoryFilter).WhereElementIsNotElementType().ToList(); // 遍历所有的梁元素 foreach (Element beam in beams) { // 判断是否和任何一个楼板元素相交 foreach (Element floor in floors) { Solid beamSolid = GetSolidFromElement(beam); Solid floorSolid = GetSolidFromElement(floor); if (beamSolid != null && floorSolid != null && beamSolid.Intersect(floorSolid) != SetComparisonResult.Disjoint) { // 梁和楼板相交,执行其他操作 // ... } } } // 获取元素的Solid对象 private Solid GetSolidFromElement(Element element) { GeometryElement geometryElement = element.get_Geometry(new Options()); foreach (GeometryObject geometryObject in geometryElement) { Solid solid = geometryObject as Solid; if (solid != null && solid.Volume > 0) { return solid; } } return null; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值