A class that allows direct construction of geometry objects (solids, open shells, etc.).
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 17.0.0.0 (17.0.1090.0)
Since: 2016
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Examples

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();
}
}

Private Sub CreateDirectShapeFromCylinder(doc As Document)
' 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
Dim brepBuilder As New BRepBuilder(BRepType.Solid)
' The surfaces of the four faces.
Dim basis As New Frame(New XYZ(50, -100, 0), New XYZ(0, 1, 0), New XYZ(-1, 0, 0), New XYZ(0, 0, 1))
Dim cylSurf As CylindricalSurface = CylindricalSurface.Create(basis, 50)
Dim top As Plane = Plane.CreateByNormalAndOrigin(New XYZ(0, 0, 1), New XYZ(0, 0, 100))
' normal points outside the cylinder
Dim bottom As Plane = Plane.CreateByNormalAndOrigin(New XYZ(0, 0, 1), New XYZ(0, 0, 0))
' normal points inside the cylinder
' Add the four faces
Dim frontCylFaceId As BRepBuilderGeometryId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(cylSurf, Nothing), False)
Dim backCylFaceId As BRepBuilderGeometryId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(cylSurf, Nothing), False)
Dim topFaceId As BRepBuilderGeometryId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(top, Nothing), False)
Dim bottomFaceId As BRepBuilderGeometryId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(bottom, Nothing), True)
' Geometry for the four semi-circular edges and two vertical linear edges
Dim frontEdgeBottom As BRepBuilderEdgeGeometry = BRepBuilderEdgeGeometry.Create(Arc.Create(New XYZ(0, -100, 0), New XYZ(100, -100, 0), New XYZ(50, -50, 0)))
Dim backEdgeBottom As BRepBuilderEdgeGeometry = BRepBuilderEdgeGeometry.Create(Arc.Create(New XYZ(100, -100, 0), New XYZ(0, -100, 0), New XYZ(50, -150, 0)))
Dim frontEdgeTop As BRepBuilderEdgeGeometry = BRepBuilderEdgeGeometry.Create(Arc.Create(New XYZ(0, -100, 100), New XYZ(100, -100, 100), New XYZ(50, -50, 100)))
Dim backEdgeTop As BRepBuilderEdgeGeometry = BRepBuilderEdgeGeometry.Create(Arc.Create(New XYZ(0, -100, 100), New XYZ(100, -100, 100), New XYZ(50, -150, 100)))
Dim linearEdgeFront As BRepBuilderEdgeGeometry = BRepBuilderEdgeGeometry.Create(New XYZ(100, -100, 0), New XYZ(100, -100, 100))
Dim linearEdgeBack As BRepBuilderEdgeGeometry = BRepBuilderEdgeGeometry.Create(New XYZ(0, -100, 0), New XYZ(0, -100, 100))
' Add the six edges
Dim frontEdgeBottomId As BRepBuilderGeometryId = brepBuilder.AddEdge(frontEdgeBottom)
Dim frontEdgeTopId As BRepBuilderGeometryId = brepBuilder.AddEdge(frontEdgeTop)
Dim linearEdgeFrontId As BRepBuilderGeometryId = brepBuilder.AddEdge(linearEdgeFront)
Dim linearEdgeBackId As BRepBuilderGeometryId = brepBuilder.AddEdge(linearEdgeBack)
Dim backEdgeBottomId As BRepBuilderGeometryId = brepBuilder.AddEdge(backEdgeBottom)
Dim backEdgeTopId As BRepBuilderGeometryId = brepBuilder.AddEdge(backEdgeTop)
' Loops of the four faces
Dim loopId_Top As BRepBuilderGeometryId = brepBuilder.AddLoop(topFaceId)
Dim loopId_Bottom As BRepBuilderGeometryId = brepBuilder.AddLoop(bottomFaceId)
Dim loopId_Front As BRepBuilderGeometryId = brepBuilder.AddLoop(frontCylFaceId)
Dim loopId_Back As BRepBuilderGeometryId = 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 tr As New Transaction(doc, "Create a DirectShape")
tr.Start()
Dim ds As DirectShape = DirectShape.CreateElement(doc, New ElementId(BuiltInCategory.OST_GenericModel))
ds.SetShape(brepBuilder)
tr.Commit()
End Using
End Sub