API - Is SelectChain method result sorted

I need to select an open chain in a sketch and extract the entities in the chain. The catch is that I need the entities in order from one end of the chain to the other. My question is does do any of you API gurus know if SelectChain returns the entities in any particular order?

Comments 2
JB
JB 2021-09-11

It doesn't return any entities at all.  It just selects them.  Order is not documented, but appears it deselects the current segment, starts at one end, and goes toward the other, adding segments to the current selection set.  It generally starts with the first entity created. However, if you edit/delete/move around the entities and connect them in different ways, it may decide to start at the other end.  Best bet is to test it yourself and understand how it behaves in all of your possible scenarii.  This is an incredibly easy test macro to write:


Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swSketch As SldWorks.Sketch
Dim swSeg As SldWorks.SketchSegment
Dim swSelMgr  As SldWorks.SelectionMgr
Sub main()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swSelMgr = swDoc.SelectionManager
Set swSeg = swSelMgr.GetSelectedObject6(1, -1)
swSeg.SelectChain True, Nothing
MsgBox "Chain Selected"
For i = swSelMgr.GetSelectedObjectCount2(-1) To 1 Step -1
    Set swSeg = swSelMgr.GetSelectedObject6(i, -1)
    swSeg.DeSelect
    MsgBox "Deselected segment " & i
Next i


End Sub

ES
ES 2021-09-13

Thanks a bunch Josh. I appreciate your knowledge as always!