MACRO LIBRARY

Get the parent sketches of a selected feature

Free public access. No account or subscription required.

Files

Get the parent sketches of a selected feature

Code

Module: mMain

'Get the parent sketches of selected feature or selected face's feature.
    
'Precondition:
'1. Part or assembly is open and feature.
'2. Feature or face is selected in feature tree.
'Result: See immediate window.
    
'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 swFeat As SldWorks.Feature
Dim swFace As SldWorks.Face2
Dim vFeatures As Variant
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    
    If swSelMgr.GetSelectedObjectType3(1, -1) = swSelFACES Then
        Set swFace = swSelMgr.GetSelectedObject6(1, -1)
        Set swFeat = swFace.GetFeature
    ElseIf swSelMgr.GetSelectedObjectType3(1, -1) = swSelBODYFEATURES Then
        Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
    Else
        Exit Sub
    End If
    
    vFeatures = swFeat.GetParents
    If IsEmpty(vFeatures) = False Then
        For i = 0 To UBound(vFeatures)
            If vFeatures(i).GetTypeName = "ProfileFeature" Then
                Debug.Print vFeatures(i).Name
            End If
        Next i
    End If
End Sub