Inventor: 获取电缆管路部件的名字

原文链接:http://adndevblog.typepad.com/manufacturing/2016/07/cable-harness-component-names.html

当遍历电缆管路部件 Cable & Harness 的时候,会看到名为“HA_VC_xxx” 的VirtualComponentDefinition。


...
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
...
这个名字和在模型树结构中的名字并不一致。这是因为列在树结构中的实际并不是具体的部件,而仅仅是对象容器。如果选中它们,执行代码,可以看到它们是 ClientBrowserNodeDefinitionObject

 Inventor: 获取电缆管路部件的名字


VirtualComponenetDefinition的Part Number实际对应的是前面提到的部件名,执行如下的代可以看到:

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

Inventor: 获取电缆管路部件的名字