BRepBuilder
A class that allows direct construction of geometry objects (solids, open shells, etc.).
Inheritance Hierarchy
System.Object
Autodesk.Revit.DB.ShapeBuilder
Autodesk.Revit.DB.BRepBuilder
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public class BRepBuilder : ShapeBuilder
The BRepBuilder type exposes the following members.
Constructors
Name
Description
Public Method
BRepBuilder
Construct a BRepBuilder to use in constructing geometry.
Properties
Name
Description
Public Property
IsValidObject
Specifies whether the .NET object represents a valid Revit entity.
(Inherited from ShapeBuilder)
Methods
Name
Description
Public Method
AddCoEdge
Add a co-edge associated to a previously added edge. A co-edge represents the use of an edge on one of the edge’s faces. BrepBuilder allows at most two faces per edge, hence at most two co-edges per edge, and the co-edges must have opposite bCoEdgeIsReversed flags. The co-edges in a loop must be added in the order in which they occur in the loop (i.e., in their topological order).
Public Method
AddEdge
Add a new edge to the geometry being built. The BRepBuilder uses edges only to store edge geometry and to track pairs of co-edges that share an edge.
Public Method
AddFace
Creates an empty face in the geometry being built. Other BRepBuilder methods are used to add loops to the face.
Public Method
AddLoop
Creates an empty loop in a given face of the geometry being built. Other BRepBuilder methods are used to add co-edges to the loop.
Public Method
AllowRemovalOfProblematicFaces
Allow BRepBuilder to remove problematic faces (e.g., due to inaccurate edge geometry). If this option is enabled and BRepBuilder removes some faces, the output geometry’s type will be OpenShell regardless of the expected type specified when the BRepBuilder was created.
Public Method
CanAddGeometry
A validator function that checks the state of this BRepBuilder object. Returns true if this BRepBuilder object is accepting b-rep data, false otherwise.
Public Method
Dispose
(Inherited from ShapeBuilder)
Public Method
Equals
Determines whether the specified object is equal to the current object.
(Inherited from Object)
Public Method
Finish
Complete construction of the geometry. The geometry will be validated and, if valid, stored in this BRepBuilder. Otherwise it will be deleted.
Public Method
FinishFace
Indicates that the caller has finished defining the given face.
Public Method
FinishLoop
Indicates that the caller has finished defining the given loop.
Public Method
GetHashCode
Serves as the default hash function.
(Inherited from Object)
Public Method
GetResult.
Get the Solid built by this BRepBuilder. This will clear the built geometry stored in the BRepBuilder. This function will throw if this BRepBuilder hasn’t completed building the b-rep. Use IsResultAvailable() to verify that this BRepBuilder contains a valid result.
Public Method
GetResult(ExternalGeometryId, BRepBuilderPersistentIds)
Get the ExternallyTaggedBRep built by this BRepBuilder. This will clear the built geometry stored in the BRepBuilder. This function will throw if this BRepBuilder hasn’t completed building the b-rep. Use IsResultAvailable() to verify that this BRepBuilder contains a valid result.
Public Method
GetType
Gets the Type of the current instance.
(Inherited from Object)
Public Method
Static Member
IsPermittedSurfaceType
A validator function that checks whether the surface object is of type supported as face surface by BRepBuilder.
Public Method
IsResultAvailable
A validator function that checks the state of this BRepBuilder object. Returns true if this BRepBuilder object has successfully built a b-rep.
Public Method
IsValidEdgeId
A validator function that checks whether the edge id corresponds to an edge previously added to this BRepBuilder object.
Public Method
IsValidFaceId
A validator function that checks whether the face id corresponds to a face previously added to this BRepBuilder object.
Public Method
IsValidLoopId
A validator function that checks whether the loop id corresponds to a loop previously added to this BRepBuilder object.
Public Method
IsValidPersistentIdsMap
A validator function that makes sure that all BRepBuilderGeometryIds in the input map can be found in this BRepBuilder object.
Public Method
RemovedSomeFaces
Returns ‘true’ if BRepBuilder removed some problematic faces from the output geometry, ‘false’ if not. If allowRemovalOfProblematicFaces was not called to enable removal of problematic faces, this function will return ‘false’. Note that if some faces were removed, the output geometry’s type will be OpenShell regardless of the expected type that was specified when the BRepBuilder was created.
Public Method
SetAllowShortEdges
Make BRepBuilder allow edges that it would normally disallow as being too short for Revit geometry.
Public Method
SetFaceMaterialId
Sets material id to a face.
Public Method
ToString
Returns a string that represents the current object.
(Inherited from Object)
Example
private void CreateDirectShapeFromCylinder(Document doc){ // Naming convention for faces and edges: we assume that x is to the left and pointing down, y is horizontal and pointing to the right, z is up BRepBuilder brepBuilder = new BRepBuilder(BRepType.Solid);
// The surfaces of the four faces. Frame basis = new Frame(new XYZ(50, -100, 0), new XYZ(0, 1, 0), new XYZ(-1, 0, 0), new XYZ(0, 0, 1)); CylindricalSurface cylSurf = CylindricalSurface.Create(basis, 50); Plane top = Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), new XYZ(0, 0, 100)); // normal points outside the cylinder Plane bottom = Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), new XYZ(0, 0, 0)); // normal points inside the cylinder
// Add the four faces BRepBuilderGeometryId frontCylFaceId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(cylSurf, null), false); BRepBuilderGeometryId backCylFaceId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(cylSurf, null), false); BRepBuilderGeometryId topFaceId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(top, null), false); BRepBuilderGeometryId bottomFaceId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(bottom, null), true);
// Geometry for the four semi-circular edges and two vertical linear edges BRepBuilderEdgeGeometry frontEdgeBottom = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(0, -100, 0), new XYZ(100, -100, 0), new XYZ(50, -50, 0))); BRepBuilderEdgeGeometry backEdgeBottom = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(100, -100, 0), new XYZ(0, -100, 0), new XYZ(50, -150, 0)));
BRepBuilderEdgeGeometry frontEdgeTop = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(0, -100, 100), new XYZ(100, -100, 100), new XYZ(50, -50, 100))); BRepBuilderEdgeGeometry backEdgeTop = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(0, -100, 100), new XYZ(100, -100, 100), new XYZ(50, -150, 100)));
BRepBuilderEdgeGeometry linearEdgeFront = BRepBuilderEdgeGeometry.Create(new XYZ(100, -100, 0), new XYZ(100, -100, 100)); BRepBuilderEdgeGeometry linearEdgeBack = BRepBuilderEdgeGeometry.Create(new XYZ(0, -100, 0), new XYZ(0, -100, 100));
// Add the six edges BRepBuilderGeometryId frontEdgeBottomId = brepBuilder.AddEdge(frontEdgeBottom); BRepBuilderGeometryId frontEdgeTopId = brepBuilder.AddEdge(frontEdgeTop); BRepBuilderGeometryId linearEdgeFrontId = brepBuilder.AddEdge(linearEdgeFront); BRepBuilderGeometryId linearEdgeBackId = brepBuilder.AddEdge(linearEdgeBack); BRepBuilderGeometryId backEdgeBottomId = brepBuilder.AddEdge(backEdgeBottom); BRepBuilderGeometryId backEdgeTopId = brepBuilder.AddEdge(backEdgeTop);
// Loops of the four faces BRepBuilderGeometryId loopId_Top = brepBuilder.AddLoop(topFaceId); BRepBuilderGeometryId loopId_Bottom = brepBuilder.AddLoop(bottomFaceId); BRepBuilderGeometryId loopId_Front = brepBuilder.AddLoop(frontCylFaceId); BRepBuilderGeometryId loopId_Back = brepBuilder.AddLoop(backCylFaceId);
// Add coedges for the loop of the front face brepBuilder.AddCoEdge(loopId_Front, linearEdgeBackId, false); brepBuilder.AddCoEdge(loopId_Front, frontEdgeTopId, false); brepBuilder.AddCoEdge(loopId_Front, linearEdgeFrontId, true); brepBuilder.AddCoEdge(loopId_Front, frontEdgeBottomId, true); brepBuilder.FinishLoop(loopId_Front); brepBuilder.FinishFace(frontCylFaceId);
// Add coedges for the loop of the back face brepBuilder.AddCoEdge(loopId_Back, linearEdgeBackId, true); brepBuilder.AddCoEdge(loopId_Back, backEdgeBottomId, true); brepBuilder.AddCoEdge(loopId_Back, linearEdgeFrontId, false); brepBuilder.AddCoEdge(loopId_Back, backEdgeTopId, true); brepBuilder.FinishLoop(loopId_Back); brepBuilder.FinishFace(backCylFaceId);
// Add coedges for the loop of the top face brepBuilder.AddCoEdge(loopId_Top, backEdgeTopId, false); brepBuilder.AddCoEdge(loopId_Top, frontEdgeTopId, true); brepBuilder.FinishLoop(loopId_Top); brepBuilder.FinishFace(topFaceId);
// Add coedges for the loop of the bottom face brepBuilder.AddCoEdge(loopId_Bottom, frontEdgeBottomId, false); brepBuilder.AddCoEdge(loopId_Bottom, backEdgeBottomId, false); brepBuilder.FinishLoop(loopId_Bottom); brepBuilder.FinishFace(bottomFaceId);
brepBuilder.Finish();
using (Transaction tr = new Transaction(doc, "Create a DirectShape")) { tr.Start(); DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); ds.SetShape(brepBuilder); tr.Commit(); }}