When run, this macro will examine the current selection set. For every solid or surface body that is selected, it will find the body feature in the feature tree. It will then de-select all the bodies and select the features instead. You can then delete the features from the tree. It will ignore any selection that's not a solid body or surface body, so activate the Solid and/or Surface body filters to select things from the graphics area.
Code: Select all
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swSels As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim cFeats As Collection
Dim swFace As SldWorks.Face2
Dim swBod As SldWorks.Body2
Dim i As Long
Dim j As Long
Dim bFound As Boolean
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swSels = swDoc.SelectionManager
Set cFeats = New Collection
For i = 1 To swSels.GetSelectedObjectCount2(-1)
If (swSels.GetSelectedObjectType3(i, -1) = swSelSOLIDBODIES) Or (swSels.GetSelectedObjectType3(i, -1) = swSelSURFACEBODIES) Then
Set swBod = swSels.GetSelectedObject6(i, -1)
Set swFace = swBod.GetFirstFace
Set swFeat = swFace.GetFeature
bFound = False
For j = 1 To cFeats.Count
If swFeat Is cFeats(j) Then
bFound = True
Exit For
End If
Next j
If Not bFound Then cFeats.Add swFeat
End If
Next i
swDoc.ClearSelection2 True
For i = 1 To cFeats.Count
cFeats(i).Select True
Next i
End Sub