Solids and faces are sometimes used as inputs to other utilities. The Revit API provides several routines which can be used to create such geometry from scratch or to derive it from other inputs.
The method
returns a copy of the input geometry element with a transformation applied. Because this geometry is a copy, its members cannot be used as input references to other Revit elements, but it can be used geometric analysis and extraction.
The GeometryCreationUtilities class is a utility class that allows construction of basic solid shapes:
The resulting geometry is not added to the document as a part of any element. However, the created Solid can be used as inputs to other API functions, including:
The following example uses the GeometryCreationUtilities class to create cylindrical shapes based on a location and height. This might be used, for example, to create volumes around the ends of a wall in order to find other walls within close proximity to the wall end points:
Code Region: Create cylindrical solid |
private Solid CreateCylindricalVolume(XYZ point, double height, double radius) { // build cylindrical shape around endpoint List<CurveLoop> curveloops = new List<CurveLoop>(); CurveLoop circle = new CurveLoop(); // For solid geometry creation, two curves are necessary, even for closed // cyclic shapes like circles circle.Append(m_app.Create.NewArc(point, radius, 0, Math.PI, XYZ.BasisX, XYZ.BasisY)); circle.Append(m_app.Create.NewArc(point, radius, Math.PI, 2 * Math.PI, XYZ.BasisX, XYZ.BasisY)); curveloops.Add(circle); Solid createdCylinder = GeometryCreationUtilities.CreateExtrusionGeometry(curveloops, XYZ.BasisZ, height); return createdCylinder; } |
The BooleanOperationsUtils class provides methods for combining a pair of solid geometry objects.
The ExecuteBooleanOperation() method takes a copy of the input solids and produces a new solid as a result. Its first argument can be any solid, either obtained directly from a Revit element or created via another operation like GeometryCreationUtils.
The method ExecuteBooleanOperationModifyingOriginalSolid() performs the boolean operation directly on the first input solid. The first input must be a solid which is not obtained directly from a Revit element. The property GeometryObject.IsElementGeometry can identify whether the solid is appropriate as input for this method.
Options to both methods include the operations type: Union, Difference, or Intersect. The following example demonstrates how to get the intersection of two solids and then find the volume.
Code Region: Volume of Solid Intersection |
private void ComputeIntersectionVolume(Solid solidA, Solid solidB) { Solid intersection = BooleanOperationsUtils.ExecuteBooleanOperation(solidA, solidB, BooleanOperationsType.Intersect); double volumeOfIntersection = intersection.Volume; } |