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

 

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