MACRO LIBRARY

Select the loops adjacent to selected face using co-edges

Free public access. No account or subscription required.

Files

Associated model(s) Select the loops adjacent to selected face using co-edges

Code

'Precondition: a face is selected
'Results: the face's loops and all loops sharing an co-edge with the face are selected
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swLoop As SldWorks.Loop2
Dim swFace As SldWorks.Face2
Dim swEdge As SldWorks.Edge
Dim swCoEdge As SldWorks.CoEdge
Dim vCoEdges As Variant
Dim vLoops As Variant
Dim vEdges As Variant
Dim i As Integer
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    
    Set swFace = swSelMgr.GetSelectedObject6(1, -1)
    vLoops = swFace.GetLoops
    Set swLoop = vLoops(0)  'assumption, not sure why the array would have more than one loop
    vEdges = swLoop.GetEdges
    Set swEdge = vEdges(0)
    swLoop.Select swEdge, False, Nothing
    
    vCoEdges = swLoop.GetCoEdges
    For i = 0 To UBound(vCoEdges)
        Set swCoEdge = vCoEdges(i)
        Set swCoEdge = swCoEdge.GetPartner
        Set swLoop = swCoEdge.GetLoop
        vEdges = swLoop.GetEdges
        Set swEdge = vEdges(0)
        swLoop.Select swEdge, True, Nothing
    Next i
End Sub
    
'A co-edge represents an edge in a loop.