Yes you can do so with TessellatedShapeBuilder but you only need the points:
Private Function Obj_230204a(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData,
ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) As Result
Dim UIApp As UIApplication = commandData.Application
Dim UIDoc As UIDocument = commandData.Application.ActiveUIDocument
If UIDoc Is Nothing Then Return Result.Cancelled Else
Dim IntDoc As Document = UIDoc.Document
Const NumberOfSides As Integer = 6
Const BaseRadius As Double = 1
Const ApexHeight As Double = 2
Dim Seg As Double = 2.0 / NumberOfSides
Dim Points As XYZ() = New XYZ(NumberOfSides - 1) {}
For i = 0 To NumberOfSides - 1
Dim P As Double = i * Seg
Dim X As Double = Math.Sin(Math.PI * P) * BaseRadius
Dim Y As Double = Math.Cos(Math.PI * P) * BaseRadius
Points(i) = New XYZ(X, Y, 0)
Next
Dim builder As New TessellatedShapeBuilder()
builder.OpenConnectedFaceSet(True)
'The bottom face
builder.AddFace(New TessellatedFace(Points, ElementId.InvalidElementId))
'Side faces
Dim ApexPt As New XYZ(0, 0, ApexHeight)
For i = 0 To Points.Length - 1
Dim J As Integer = i + 1
If i = Points.Length - 1 Then
J = 0
End If
Dim P1 As XYZ = Points(i)
Dim P2 As XYZ = Points(J)
builder.AddFace(New TessellatedFace(New XYZ(2) {P1, P2, ApexPt}, ElementId.InvalidElementId))
Next
builder.CloseConnectedFaceSet()
builder.Target = TessellatedShapeBuilderTarget.Solid
builder.Fallback = TessellatedShapeBuilderFallback.Abort
builder.Build()
Dim Res As TessellatedShapeBuilderResult = builder.GetBuildResult
If Res.Outcome = TessellatedShapeBuilderOutcome.Solid Then
Using Tx As New Transaction(IntDoc, "Pyramid")
If Tx.Start = TransactionStatus.Started Then
Dim ds As DirectShape = DirectShape.CreateElement(IntDoc, New ElementId(BuiltInCategory.OST_GenericModel))
ds.SetShape(Res.GetGeometricalObjects())
Tx.Commit()
End If
End Using
End If
Return Result.Succeeded
End Function
public Result Obj_230204a(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
UIApplication UIApp = commandData.Application;
UIDocument UIDoc = commandData.Application.ActiveUIDocument;
if (UIDoc == null)
return Result.Cancelled;
Document IntDoc = UIDoc.Document;
const int NumberOfSides = 6;
const double BaseRadius = 1;
const double ApexHeight = 2;
double Seg = 2.0 / NumberOfSides;
XYZ[] Points = new XYZ[NumberOfSides];
for (int i = 0; i <= NumberOfSides - 1; i++)
{
double P = i * Seg;
double X = Math.Sin(Math.PI * P) * BaseRadius;
double Y = Math.Cos(Math.PI * P) * BaseRadius;
Points[i] = new XYZ(X, Y, 0);
}
TessellatedShapeBuilder builder = new TessellatedShapeBuilder();
builder.OpenConnectedFaceSet(true);
//The bottom face
builder.AddFace(new TessellatedFace(Points, ElementId.InvalidElementId));
//Side faces
XYZ ApexPt = new XYZ(0, 0, ApexHeight);
for (int i = 0; i <= Points.Length - 1; i++)
{
int J = i + 1;
if (i == Points.Length - 1)
{
J = 0;
}
XYZ P1 = Points[i];
XYZ P2 = Points[J];
builder.AddFace(new TessellatedFace(new XYZ[3] {
P1,
P2,
ApexPt
}, ElementId.InvalidElementId));
}
builder.CloseConnectedFaceSet();
builder.Target = TessellatedShapeBuilderTarget.Solid;
builder.Fallback = TessellatedShapeBuilderFallback.Abort;
builder.Build();
TessellatedShapeBuilderResult Res = builder.GetBuildResult();
if (Res.Outcome == TessellatedShapeBuilderOutcome.Solid)
{
using (Transaction Tx = new Transaction(IntDoc, "Pyramid"))
{
if (Tx.Start() == TransactionStatus.Started)
{
DirectShape ds = DirectShape.CreateElement(IntDoc, new ElementId(BuiltInCategory.OST_GenericModel));
ds.SetShape(Res.GetGeometricalObjects());
Tx.Commit();
}
}
}
return Result.Succeeded;
}
hi RPTHOMAS108, thank you for your assistance, I will try it.
Thank you for the beautiful little sample. Shared it on the blog:
https://thebuildingcoder.typepad.com/blog/2023/02/pyramid-builder-commandloader-et-al.html#3
Thank you!