I have been trying with no luck. I want to take this good code, and instead of having the Private Sub,
put it into it's own module and the module would be called from the Main.
'This will select a pre-defined sketch name in a component of an assembly.
Public swApp As SldWorks.SldWorks
Public swModel As SldWorks.ModelDoc2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Debug.Print "Active model: " & swModel.GetTitle
TraverseModel swModel, 1
End Sub
Private Sub TraverseModel(model As Object, nLevel As Integer)
Dim swFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim swComp As SldWorks.Component2
Dim strPad As String
For i = 1 To nLevel
strPad = strPad & vbTab
Next i
Set swFeat = model.FirstFeature
'''''''''''''''''''''''''''''''''''''''''''
Do While Not swFeat Is Nothing
If swFeat.Name = "CutSketch1" Then '''''Change your sketch name
swFeat.Select False
End If
'''''''''''''''''''''''''''''''''''''''''''
Debug.Print strPad & swFeat.Name & " (" & swFeat.GetTypeName & ")"
If swFeat.GetTypeName = "Reference" Then
Set swComp = swFeat.GetSpecificFeature2
TraverseModel swComp, nLevel + 1
Else
Set swSubFeat = swFeat.GetFirstSubFeature
Do While Not swSubFeat Is Nothing
Debug.Print strPad & vbTab & swSubFeat.Name & " (" & swSubFeat.GetTypeName & ")"
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
End If
Set swFeat = swFeat.GetNextFeature
Loop
End Sub
