So here's my code so far.
Public invApp As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
Public _AsmDoc As AssemblyDocument = invApp.ActiveDocument
Public counter As Integer = 0
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
invApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
If _AsmDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("Not an assembly file. Closing...")
Console.WriteLine("should not ever hit this")
Me.Close()
Exit Sub
End If
Call Iterate(_AsmDoc.ComponentDefinition.Occurrences)
End Sub
Private Sub Iterate(Occurrences As ComponentOccurrences)
For Each occ As ComponentOccurrence In Occurrences
If TypeOf occ.Definition IsNot VirtualComponentDefinition Then
Dim doc As Document = occ.Definition.Document
If (doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
Iterate(doc.ComponentDefinition.Occurrences)
Else
Dim SB As SurfaceBody
Dim SBs As SurfaceBodies = doc.ComponentDefinition.SurfaceBodies
For Each SB In SBs
SB.Name = doc.DisplayName
counter = counter + 1
Debug.WriteLine(counter)
Next
End If
End If
Next
End Sub
The code essentially runs through each part and renames the solid body name to the parts name but keeps getting stuck and I'm not 100% sure why the error reads out...
It runs through most of the parts in the assembly but stops about 75% through.
User contributions licensed under CC BY-SA 3.0