By Adam Nagy
Inside Inventor 2016 you can reference other CAD file formats directly from an assembly. In this case you can also see the structure of the referenced assembly in the model tree. If you'd also need to get back the structure using the original file names - i.e. going from Occurrence to the original file - that is currently not exposed in the API: no direct access from"SubOccurrence1" to"AnyCAD Part1" in the blow picture.
One workaround could be finding the original files based on the Occurrence.Name, since both that and the Inventor document names created from the foreign file are based on the name of the original file. You can find the list of the original file names through Document.File.AllReferencedFiles:
Function GetFileName(filePath As String) As String Dim i1 As Integer i1 = InStrRev(filePath, "\") Dim i2 As Integer i2 = InStrRev(filePath, ".")' Check for occurrence name as well If i2 < 1 Then i2 = InStrRev(filePath, ":") GetFileName = Mid(filePath, i1 + 1, i2 - i1 - 1) End Function Function GetFullPath(fileName As String) As String Dim asm As AssemblyDocument Set asm = ThisApplication.ActiveDocument Dim f As File For Each f In asm.File.AllReferencedFiles If GetFileName(f.FullFileName) = fileName Then GetFullPath = f.FullFileName Exit Function End If Next End Function Sub PrintOccurrences( _ occs As ComponentOccurrences, _ i As Integer) Dim occ As ComponentOccurrence For Each occ In occs Debug.Print Space(i); occ.name Dim doc As Document Set doc = occ.Definition.Document Dim fullPath As String If doc.IsEmbeddedDocument Then Dim fileName As String fileName = GetFileName(occ.name) fullPath = GetFullPath(fileName) Else fullPath = doc.FullFileName End If Debug.Print Space(i); " - " + fullPath Call PrintOccurrences( _ occ.SubOccurrences, _ i + 2) Next End Sub Sub PrintStructure() Dim doc As AssemblyDocument Set doc = ThisApplication.ActiveDocument Dim acd As AssemblyComponentDefinition Set acd = doc.ComponentDefinition Call PrintOccurrences(acd.Occurrences, 1) End Sub
I get this output in case of my assembly that is referencing a SolidWorks assembly file called gears.SLDASM:
gears:1 - C:\SolidWorks\Gears\gears.SLDASM frame:1 - C:\SolidWorks\Gears\frame.SLDPRT Internal Spur Gear:1 - C:\SolidWorks\Gears\Internal Spur Gear.sldprt Spur Gear:1 - C:\SolidWorks\Gears\Spur Gear.sldprt Spur Gear:2 - C:\SolidWorks\Gears\Spur Gear.sldprt Spur Gear:3 - C:\SolidWorks\Gears\Spur Gear.sldprt Spur Gear:4 - C:\SolidWorks\Gears\Spur Gear.sldprt shaft1:1 - C:\SolidWorks\Gears\shaft1.SLDPRT shaft2:1 - C:\SolidWorks\Gears\shaft2.SLDPRT shaft2:2 - C:\SolidWorks\Gears\shaft2.SLDPRT shaft2:3 - C:\SolidWorks\Gears\shaft2.SLDPRT