Revit二次开发:由房间获取房间的墙

之前用的方法是由房间边界构成的Solid,计算与该Solid相交的Element,然后判断是否为墙。相对来说这个方法比较通用,可以检索出房间的楼板、窗户等各种构件。

SpatialElementBoundaryOptions se=new SpatialElementBoundaryOptions();
                se.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
                SpatialElementGeometryCalculator calculator =new  SpatialElementGeometryCalculator(document,se);
                Solid solid = calculator.CalculateSpatialElementGeometry(room)?.GetGeometry();
                var list = new FilteredElementCollector(document).WhereElementIsNotElementType().
                    WherePasses(new ElementIntersectsSolidFilter(solid)).ToList();

                foreach (var element in list)
                {
                    Wall wall=element as Wall;
                    if (wall!=null)
                    {
                        wallsOfRoom.Add(wall);
                    }
                }

看了Jeremy大神的博客,才知道,如果只是找墙的话,其实用BoundarySegment.ElementId,就可以直接得到构成这个边界部分的元素(墙)。

IList<IList<BoundarySegment>> loops = 
                    room.GetBoundarySegments(new SpatialElementBoundaryOptions());
                foreach (IList<BoundarySegment> loop in loops)
                {
                    foreach (BoundarySegment segment in loop)
                    {
                        Wall wall =document.GetElement(segment.ElementId)  as Wall;
                        if (wall != null)
                        {
                            wallsOfRoom.Add(wall);
                        }
                    }
                }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值