This walkthrough illustrates how to get geometry data from a wall. The following information is covered:
In order to get the wall's geometry information, you must create a Geometry.Options object which provides detailed customized options. The code is as follows:
Code Region 20-1: Creating Geometry.Options |
Autodesk.Revit.DB.Options geomOption = application.Create.NewGeometryOptions(); if (null != geomOption) { geomOption.ComputeReferences = true; geomOption.DetailLevel = Autodesk Autodesk.Revit.DB.DetailLevels.Fine; // Either the DetailLevel or the View can be set, but not both //geomOption.View = commandData.Application.ActiveUIDocument.Document.ActiveView; TaskDialog.Show("Revit", "Geometry Option created successfully."); } |
Wall geometry is a solid made up of faces and edges. Complete the following steps to get the faces and edges:
The sample code follows:
Code Region 20-2: Retrieving faces and edges |
private void GetFacesAndEdges(Wall wall) { String faceInfo = ""; Autodesk.Revit.DB.Options opt = new Options(); Autodesk.Revit.DB.GeometryElement geomElem = wall.get_Geometry(opt); foreach (GeometryObject geomObj in geomElem) { Solid geomSolid = geomObj as Solid; if (null != geomSolid) { int faces = 0; double totalArea = 0; foreach (Face geomFace in geomSolid.Faces) { faces++; faceInfo += "Face " + faces + " area: " + geomFace.Area.ToString() + "\n"; totalArea += geomFace.Area; } faceInfo += "Number of faces: " + faces + "\n"; faceInfo += "Total area: " + totalArea.ToString() + "\n"; foreach (Edge geomEdge in geomSolid.Edges) { // get wall's geometry edges } } } TaskDialog.Show("Revit", faceInfo); } |