Creigbm
Mechanical
- Aug 1, 2003
- 161
I am trying to create a treeview of all the components and parts in an assembly. Listed below is the code I used (straight from SW help) and I am wodering why it will only go 2 levels deep. In other words, if you have a part in a subassembly it will return 'SubAssy1/Part1' rather than breaking it up into 2 model names. Any ideas? Thanks.
Code:
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swConf As SldWorks.Configuration
Dim swRootComp As SldWorks.Component2
Dim bRet As Boolean
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent
TraverseComponent swRootComp, 1
End Sub
Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim swCompConfig As SldWorks.Configuration
Dim i As Long
vChildComp = swComp.GetChildren
For i = 0 To UBound(vChildComp)
Set swChildComp = vChildComp(i)
TraverseComponent swChildComp, nLevel + 1
Debug.Print Mid(swChildComp.Name2, 1, Len(swChildComp.Name2) - 2)
Next i
End Sub