Obtain 3D points along an edge

By Xiaodong Liang

Issue

I would like to obtain a listing of 3D points along a selected edge of this geometry.  Is there any functionality that would allow me to get Points from an edge at a controlled interval (e.g. return X,Y coords based on Z or return X,Y,Z based on an interval)?

Solution

The following code illustrates. Just select an Edge in your model, and the coordinates of points are output at fixed intervals along the curve (the number of intervals is determined by max_steps, which you can set in the code).

Sub GetPointsOnEdge()       ' assumes you have had Inventor application          Dim oDoc As PartDocument        oDoc = _InvApplication.ActiveDocument        Dim oCD As PartComponentDefinition        oCD = oDoc.ComponentDefinition        Dim oEdge As Edge        oEdge = oDoc.SelectSet(1)        Dim oCurveEvaluator As CurveEvaluator        oCurveEvaluator = oEdge.Evaluator        Dim length As Double        Call oCurveEvaluator.GetLengthAtParam(0, 1, length)        Debug.Print(length)        Dim max_steps As Long        max_steps = 100        Dim par_array(max_steps) As Double             Dim I As Long        For I = 0 To max_steps            Dim pos As Double            pos = I * length / max_steps            Dim par_out As Double            Call oCurveEvaluator.GetParamAtLength(0,                                        pos, par_out)            par_array(I) = par_out        Next I             ' each param refers to one point with X.Y,Z values        Dim point_array(max_steps * 3) As Double             Call oCurveEvaluator.GetPointAtParam(par_array,                                             point_array)     
   ' output the points          For I = 0 To max_steps            Debug.Print("Par = " & par_array(I) &                         " Pos = (" & point_array(I * 3) & "," &                            point_array(I * 3 + 1) & "," &                             point_array(I * 3 + 2) & ")")        Next I    End Sub

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading