Files
Select component body feature using IModelDocExtension::SelectByID2
Code
Module:
'Demonstrates how to select a component body feature using _
IModelDocExtension::SelectByID2.
'Preconditions: Assembly is open and a component body feature _
is selected in the feature tree.
'Result: Feature is re-selected programmatically.
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swSelMgr As SelectionMgr
Dim swFeat As Feature
Dim swComp As Component2
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
If swFeat Is Nothing Then
Debug.Print "Feature not selected."
Exit Sub
End If
Set swComp = swSelMgr.GetSelectedObjectsComponent4(1, -1)
If swComp Is Nothing Then
Debug.Print "Feature is not owned by a component."
Exit Sub
End If
swModel.ClearSelection2 Empty
swModel.Extension.SelectByID2 swFeat.Name & "@" & swComp.GetSelectByIDString, _
"BODYFEATURE", Empty, Empty, Empty, False, Empty, Nothing, Empty
End Sub