Message 1 of 7

Not applicable
03-19-2021
05:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The macro pasted below is meant to select the wall/floor/ceiling that corresponds to each face of the Solid object obtained from a room. (I need the face as well as its host element for the application I am working on). It occasionally fails to find walls that correspond to specific faces, as seen in the image (Revit 2020 file attached). I am unable to figure out how to prevent this.
More specifically spatialElementBoundarySubfaceList.Count is zero unexpectedly for these walls.
public void SelectRoomBoundingElements()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<Autodesk.Revit.DB.Element> collection = collector.OfClass(typeof(SpatialElement)).ToElements();
var boundingElemIds = new List<ElementId>();
foreach (Autodesk.Revit.DB.Element roomElem in collection)
{
Autodesk.Revit.DB.Architecture.Room room = roomElem as Autodesk.Revit.DB.Architecture.Room;
if (null == room)
continue;
SpatialElementGeometryCalculator calculator = new SpatialElementGeometryCalculator(doc);
SpatialElementGeometryResults results = calculator.CalculateSpatialElementGeometry(room);
Solid spaceSolid = results.GetGeometry();
foreach (Face face in spaceSolid.Faces)
{
IList<SpatialElementBoundarySubface> spatialElementBoundarySubfaceList = results.GetBoundaryFaceInfo(face);
if (spatialElementBoundarySubfaceList.Count == 0)
continue;
boundingElemIds.Add(spatialElementBoundarySubfaceList[0].SpatialBoundaryElement.HostElementId);
}
uidoc.Selection.SetElementIds(boundingElemIds);
}
}
Solved! Go to Solution.