Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is it possible to create a solid from the edges of Pyramids?

3 REPLIES 3
Reply
Message 1 of 4
VanQuyet.Doan
246 Views, 3 Replies

Is it possible to create a solid from the edges of Pyramids?

Screenshot_1.png

3 REPLIES 3
Message 2 of 4
RPTHOMAS108
in reply to: VanQuyet.Doan

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

 

 

Message 3 of 4
VanQuyet.Doan
in reply to: RPTHOMAS108

hi RPTHOMAS108, thank you for your assistance, I will try it.

Message 4 of 4
jeremy_tammik
in reply to: RPTHOMAS108

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!

  

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community