Solid and face creation

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.

Transformed geometry

The method

  • GeometryElement.GetTransformed()

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.

Geometry creation utilities

The GeometryCreationUtilities class is a utility class that allows construction of basic solid shapes:

  • Extrusion
  • Loft
  • Revolution
  • Sweep
  • Blend
  • SweptBlend

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:

  • As the input face(s) to the methods in the Analysis Visualization framework (SpatialFieldManager.AddSpatialFieldPrimitive()) – this allows the user to visualize the created shape relative to other elements in the document
  • As the input solid to finding 3D elements by intersection
  • As one or more of the inputs to a Boolean operation
  • As a part of a geometric calculation (using, for example, Face.Project(), Face.Intersect(), or other Face, Solid, and Edge geometry methods)

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

// Build cylinder centered at wall end point, extending 3' in diameter
CurveLoop cylinderLoop = new CurveLoop();
XYZ arcCenter = new XYZ(endPoint.X, endPoint.Y, elevation);
Application application = wall.Document.Application;
Arc firstArc = Arc.Create(arcCenter, 1.5, 0, Math.PI, XYZ.BasisX, XYZ.BasisY);
Arc secondArc = Arc.Create(arcCenter, 1.5, Math.PI, 2 * Math.PI, XYZ.BasisX, XYZ.BasisY);

cylinderLoop.Append(firstArc);
cylinderLoop.Append(secondArc);

List<CurveLoop> singleLoop = new List<CurveLoop>();
singleLoop.Add(cylinderLoop);

Solid proximityCylinder = GeometryCreationUtilities.CreateExtrusionGeometry(singleLoop, XYZ.BasisZ, height);

Boolean operations

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;

}
The methods CutWithHalfSpace() and CutWithHalfSpaceModifyingOriginalSolid() produce a solid which is the intersection of the input Solid with the half-space on the positive side of the given Plane. The positive side of the plane is the side to which Plane.Normal points. The first method creates a new Solid with the results, while the second modifies the existing solid (which must be a solid created by the application instead of one obtained from a Revit element).