An unhandled exception of type 'System.Exception' occurred in Microsoft.VisualBa

An unhandled exception of type 'System.Exception' occurred in Microsoft.VisualBa

Anonymous
Not applicable
1,090 Views
2 Replies
Message 1 of 3

An unhandled exception of type 'System.Exception' occurred in Microsoft.VisualBa

Anonymous
Not applicable

Hopefully this is easy.  I have the exact same logic elsewhere, no problem.  It is as if the program is not seeing the open instance of Inventor.

 

Code:

Imports System.IO
Imports System.Runtime.InteropServices


Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Ds_view_partmtl.partmtl' table. You can move, or remove it, as needed.
        Me.PartmtlTableAdapter.Fill(Me.Ds_view_partmtl.partmtl)

    End Sub

    Private Sub cmdRunComp_Click(sender As Object, e As EventArgs) Handles cmdRunComp.Click
        ' Open BOM In Vantage



        ' Open BOM in Inventor
        OpenBOM_Inventor()


    End Sub

    Private Function OpenBOM_Inventor()
        ' Define application
        Dim oApp As Inventor.Application = GetObject(, "Inventor Application")
        Dim oDoc As Inventor.AssemblyDocument = oApp.ActiveDocument

        ' Define Component Definition
        Dim oDocDef As Inventor.AssemblyComponentDefinition = oDoc.ComponentDefinition

        ' Define Leaf Occurrences
        Dim oDocLeaf As Inventor.ComponentOccurrencesEnumerator = oDocDef.Occurrences.AllLeafOccurrences

        ' Iterate through the Leaf Occurrences and print the name
        Dim i As Integer = 0
        Dim oCompOcc As Inventor.ComponentOccurrence = Nothing
        For Each oCompOcc In oDocLeaf
            i += 1
            Debug.Print("Occurrence:" + i + ": " + oCompOcc.Name)

        Next

    End Function

End Class

 

Pic:

Screen Shot 12-13-16 at 11.38 AM.JPG

0 Likes
Accepted solutions (1)
1,091 Views
2 Replies
Replies (2)
Message 2 of 3

frederic.vandenplas
Collaborator
Collaborator
Accepted solution

Hi,

 

you need to repliceerde the space with a dot Inventor.Application

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
Message 3 of 3

Anonymous
Not applicable

Thanks!

0 Likes