The Revit API provides access to the 3D geometry of spatial elements (rooms and spaces).
The SpatialElementGeometryCalculator class can be used to calculate the geometry of a spatial element and obtain the relationships between the geometry and the element's boundary elements. There are 2 options which can be provided to this utility:
The results of calculating the geometry are contained in the class SpatialElementGeometryResults. From the SpatialElementGeometryResults class, you can obtain:
Each subface offers:
Some notes about the use of this utility:
The following example calculates a room's geometry and finds its boundary faces
Code Region: Face Area using SpatialElementGeometryCalculator |
SpatialElementGeometryCalculator calculator = new SpatialElementGeometryCalculator(doc); // compute the room geometry SpatialElementGeometryResults results = calculator.CalculateSpatialElementGeometry(room); // get the solid representing the room's geometry Solid roomSolid = results.GetGeometry(); foreach (Face face in roomSolid.Faces) { double faceArea = face.Area; // get the sub-faces for the face of the room IList<SpatialElementBoundarySubface> subfaceList = results.GetBoundaryFaceInfo(face); foreach (SpatialElementBoundarySubface subface in subfaceList) { if (subfaceList.Count > 1) // there are multiple sub-faces that define the face { // get the area of each sub-face double subfaceArea = subface.GetSubface().Area; // sub-faces exist in situations such as when a room-bounding wall has been // horizontally split and the faces of each split wall combine to create the // entire face of the room } } } |
The following example calculates a room's geometry and finds its the material of faces that belong to the elements that define the room.
Code Region: Face Material using SpatialElementGeometryCalculator |
public void MaterialFromFace() { string s = ""; Document doc = this.Document; UIDocument uidoc = new UIDocument(doc); Room room = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element).ElementId) as Room; SpatialElementBoundaryOptions spatialElementBoundaryOptions = new SpatialElementBoundaryOptions(); spatialElementBoundaryOptions.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish; SpatialElementGeometryCalculator calculator = new SpatialElementGeometryCalculator(doc, spatialElementBoundaryOptions); SpatialElementGeometryResults results = calculator.CalculateSpatialElementGeometry(room); Solid roomSolid = results.GetGeometry(); foreach (Face roomSolidFace in roomSolid.Faces) { foreach (SpatialElementBoundarySubface subface in results.GetBoundaryFaceInfo(roomSolidFace)) { Face boundingElementface = subface.GetBoundingElementFace(); ElementId id = boundingElementface.MaterialElementId; s += doc.GetElement(id).Name + ", id = " + id.IntegerValue.ToString() + "\n"; } } TaskDialog.Show("revit",s); } |