Code:
Dim swApp As SldWorks.SldWorksDim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.feature
Dim featName As String
Dim featType As String
Dim featParents As Variant
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim n As Integer
Sub main()
Debug.Print " ---- Start -----------"
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swModelDocExt = swModel.Extension
' Get the selected feature
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
If swFeat Is Nothing Then
MsgBox "Kein Feature ausgewählt"
Exit Sub
End If
' Get the feature's type and name
featType = swFeat.GetTypeName()
Debug.Print "Feature type: " & featType
featName = swFeat.GetNameForSelection(featType)
' Print the feature's type and name
' to the Immediate window
Debug.Print "Feature name: " & featName
Debug.Print "------------"
featParents = swFeat.GetParents
For n = 0 To UBound(featParents)
featType = featParents(n).GetTypeName2()
Debug.Print "- Feature type: " & featType
featName = featParents(n).GetNameForSelection(featType)
Debug.Print "- Feature name: " & featName
Next n
End Sub