replicate the NewCurveByPoints method on a Revit document

replicate the NewCurveByPoints method on a Revit document

MiguelGT17
Advocate Advocate
773 Views
6 Replies
Message 1 of 7

replicate the NewCurveByPoints method on a Revit document

MiguelGT17
Advocate
Advocate

Is there a way to replicate the NewCurveByPoints method in a Revit document file so I can visualize a fancy 3D path. So far the NewModelCurve() relies on points that lay on the same plane so I only visualize a flat modelcurve instead of a 3D path that might contain steep slopes along the way.

MiguelGT17_0-1642050576961.png

MiguelGT17_1-1642050596709.png

kind regards,

Miguel G

 

0 Likes
Accepted solutions (1)
774 Views
6 Replies
Replies (6)
Message 2 of 7

jeremy_tammik
Alumni
Alumni

If it is for visualisation only, you can simply create a string of short connected ModelCurve straight line segments... the inverse of curve tessellation. The minimum curve length is slightly over 1 mm. If you create 1 cm long little bits between 2 mm and 10 cm in length, that should fit most purposes.

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 7

RPTHOMAS108
Mentor
Mentor

As you are doing this via the API why not just create the curve by points dynamically in the family environment in the background and load it into the project?

 

I don't believe you can get these curves by points directly in the project although I recall walkthrough camera path uses a similar curve in the project.

Message 4 of 7

RPTHOMAS108
Mentor
Mentor
Accepted solution

Example:

 

Public Function Obj_220113a(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result

        Dim app = commandData.Application
        Dim uidoc = commandData.Application.ActiveUIDocument
        Dim IntDoc = uidoc.Document

        Dim Pts As New List(Of XYZ)
        While True
            Try
                Pts.Add(uidoc.Selection.PickObject(Selection.ObjectType.PointOnElement, "Pick point (esc. to exit)").GlobalPoint)
            Catch ex As Exception
                Exit While
            End Try
        End While
        If Pts.Count = 0 Then
            Return Result.Cancelled
        End If

        Dim MinX As Double = Pts.Min(Function(k) k.X)
        Dim MinY As Double = Pts.Min(Function(k) k.Y)
        Dim MinZ As Double = Pts.Min(Function(k) k.Z)

        Dim TPath As String = app.Application.FamilyTemplatePath & "\" & "Metric Generic Model Adaptive.rft"
        Dim FDoc As Document = app.Application.NewFamilyDocument(TPath)

        Using Tx As New Transaction(FDoc, "Curve")
            If Tx.Start = TransactionStatus.Started Then
                Dim RPArray As New ReferencePointArray
                For i = 0 To Pts.Count - 1
                    Dim Orig As XYZ = Pts(i)
                    Dim NewPt As New XYZ(Orig.X - MinX, Orig.Y - MinY, Orig.Z - MinZ)
                    RPArray.Append(FDoc.FamilyCreate.NewReferencePoint(NewPt))
                Next

                FDoc.FamilyCreate.NewCurveByPoints(RPArray)
                Tx.Commit()
            End If
        End Using

        Dim F As Family = FDoc.LoadFamily(IntDoc)

        Dim SybId As ElementId = F.GetFamilySymbolIds()(0)
        Dim FS As FamilySymbol = IntDoc.GetElement(SybId)
        Dim G As Guid = Guid.NewGuid

        Using Tx As New Transaction(IntDoc, "Place")
            If Tx.Start = TransactionStatus.Started Then
                F.Name = "RPT" & G.ToString
                FS.Name = "RPT_T" & G.ToString

                FS.Activate()
                IntDoc.Create.NewFamilyInstance(New XYZ(MinX, MinY, MinZ), FS, StructuralType.NonStructural)

                Tx.Commit()
            End If
        End Using
        FDoc.Close(False)


        Return Result.Succeeded

    End Function

220113b.png220113a.png

 

Message 5 of 7

MiguelGT17
Advocate
Advocate

Fair enough, If  generating multiple Sketch planes to draw those small segments lines do not increase the file document, I'm going for it. I will be aware of that, thanks for the suggestion Jeremy.

 

Miguel G.

0 Likes
Message 6 of 7

MiguelGT17
Advocate
Advocate

Appreciate your approach Thomas, I was about to do the same using PostCommand and Windows API to pick up the generic adaptive model file. Turns out, the application namespace provide us the necessary tools. Thanks, again I'll be testing this approach as well.

Best regards,

Miguel G

 

 

0 Likes
Message 7 of 7

RPTHOMAS108
Mentor
Mentor

Yes if the template path wasn't there I'd probably have included the template as a resource so that it's location is known.

0 Likes