By Adam Nagy
When iterating through the components of a Cable & Harness assembly you'll find VirtualComponentDefinition's named like "HA_VC_xxx":
... Hard Drive:2 CD Ribbon Cable CD Ribbon Cable Ribbon Cable Connector:1 Ribbon Cable Connector:2 Ribbon Cable Connector:3 HA_VC_100:1 Power Supply Harness Power Supply Connector:1 ...
This does not line up with what you see in the Browser Tree. It's because what's listed there are not actually the components but just placeholders. If you select them and run a code like this then you can see that those parts are just ClientBrowserNodeDefinitionObject's:
The Part Number of the VirtualComponentDefinition's resemble more how those components are represented in the Browser Tree, so you could use that instead:
Sub PrintHierarchyTreeRecursive(occs, indent) Dim occ As ComponentOccurrence For Each occ In occs Dim pss As PropertySets If TypeOf occ.Definition Is VirtualComponentDefinition Then Set pss = occ.Definition.PropertySets Else Set pss = occ.Definition.Document.PropertySets End If Dim partNumber As String partNumber = pss("Design Tracking Properties")("Part Number").value Write #1, Spc(indent); occ.Name + ", " + partNumber Call PrintHierarchyTreeRecursive(occ.SubOccurrences, indent + 2) Next End Sub Sub PrintHierarchyTree() Dim asm As AssemblyDocument Set asm = ThisApplication.ActiveDocument Open "C:\temp\assemblyparts.txt" For Output As #1 Call PrintHierarchyTreeRecursive(asm.ComponentDefinition.Occurrences, 0) Close #1 End Sub