iLogic VB.net Inventor Solid Body Code

-1

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...

Managed Debugging Assistant 'FatalExecutionEngineError' : 'The runtime has encountered a fatal error. The address of the error was at 0x72f715da, on thread 0x7640. The error code is 0x800703e9. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.'

It runs through most of the parts in the assembly but stops about 75% through.

vb.net
autodesk
solid-bodies
asked on Stack Overflow Aug 13, 2018 by WizTheKid

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0