Finding the endpoints of a selected set of Sketch Entities

Finding the endpoints of a selected set of Sketch Entities

littlemandave
Contributor Contributor
638 Views
3 Replies
Message 1 of 4

Finding the endpoints of a selected set of Sketch Entities

littlemandave
Contributor
Contributor

I'm trying to write something (in C#) that will get the selected items in a sketch, verify that they are a connected set of lines/arcs/splines/etc that is not a closed path, and finally get the "free" endpoints of the selection.

 

Is there any API support for this? Or do I need to manually step through the start and end points of the individual entities, and figure it out myself?

 

Thanks for any insight!

0 Likes
Accepted solutions (1)
639 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni

I believe you should be able to create a path given one of the curves as the initial input and it will find all of the connections.  You can query the resulting path to determine the sketch entities at the end and get the open ends.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 4

littlemandave
Contributor
Contributor

Thanks Brian!

 

I can create a path object, and then I'm assuming that because it is an ordered collection, the start point of the first entity will be my first open point, and the end point of the last entity will be the other. Correct?

 

0 Likes
Message 4 of 4

ekinsb
Alumni
Alumni
Accepted solution

To make sure I was telling you the correct thing I went ahead and wrote a small function to test this.  Below is a VBA sub and function.  The Sub gathers the input and calls the function which computes the points and passes them back, and then the sub highlights them. 

 

 

Public Sub PathTest()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    Dim skEnt As SketchEntity
    Set skEnt = ThisApplication.CommandManager.Pick(kSketchCurveFilter, "Select sketch curve")
    
    Dim startPoint As SketchPoint
    Dim endPoint As SketchPoint
    
    If GetEndPointsOfPath(skEnt, startPoint, endPoint) = True Then
        Dim hs As HighlightSet
        Set hs = partDoc.CreateHighlightSet
    
        hs.AddItem startPoint
        hs.AddItem endPoint
    
        MsgBox "Test"
        hs.Clear
    End If
End Sub




Public Function GetEndPointsOfPath(ByVal SeedCurve As SketchEntity, ByRef Point1 As SketchPoint, ByRef Point2 As SketchPoint) As Boolean
    On Error GoTo ErrorFound
    
    Dim partDef As PartComponentDefinition
    Set partDef = SeedCurve.Parent.Parent
    
    Dim pth As Path
    Set pth = partDef.Features.CreatePath(SeedCurve)
    
    Dim pathEnt As PathEntity
    Set pathEnt = pth.Item(1)
    If pathEnt.SketchEntity.StartSketchPoint.AttachedEntities.Count = 1 Then
        Set Point1 = pathEnt.SketchEntity.StartSketchPoint
    Else
        Set Point1 = pathEnt.SketchEntity.EndSketchPoint
    End If
    
    Set pathEnt = pth.Item(pth.Count)
    If pathEnt.SketchEntity.StartSketchPoint.AttachedEntities.Count = 1 Then
        Set Point2 = pathEnt.SketchEntity.StartSketchPoint
    Else
        Set Point2 = pathEnt.SketchEntity.EndSketchPoint
    End If
    
    GetEndPointsOfPath = True
    Exit Function
    
ErrorFound:
    If Err Then
        GetEndPointsOfPath = False
        Exit Function
    End If
End Function

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog