Migrating from iLogic to VB.Net - open idw in Inventor

Migrating from iLogic to VB.Net - open idw in Inventor

andrew_canfield
Collaborator Collaborator
189 Views
1 Reply
Message 1 of 2

Migrating from iLogic to VB.Net - open idw in Inventor

andrew_canfield
Collaborator
Collaborator

Hello

I have a file path - trying to open the file (using VB.Net)!

 

The code below is from Youtube & a message box will display a column of filepaths & models.

 

Problems start after adding lines 79, 80 & mainly 89 - just trying to open the drawing just to see it (still testing).

How does VB.Net know to use Inventor to open the file?

 

The next stage will be to swap out the model on the drawing with the open in the list - code already supplied in VBA.

 

My guess is VBA & iLogic already know where Inventor is but Visual Studio (VB.Net) needs some instruction.

 

(Currently thinking this could just run as an .exe - not need to jump though the add-in hoops just yet.)

 

 

Imports Microsoft.Office.Interop

Imports Excel = Microsoft.Office.Interop.Excel
Imports Inventor
Imports System.Runtime.InteropServices
Imports System.Reflection
Imports System.Diagnostics


Public Class Form1

    Dim _InvApp As Inventor.Application
    Dim drawingFilename As String

    Private Structure ExcelRows
        Dim C1 As String
        Dim C2 As String
    End Structure
    Private ExcelRowList As List(Of ExcelRows) = New List(Of ExcelRows)

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Me.OpenFileDialog1.FileName = Nothing

        If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.TextBox1.Text = Me.OpenFileDialog1.FileName
        End If

        If GetInfo() = True Then
            For Each Xitem In ExcelRowList
                Dim lvitem As ListViewItem
                lvitem = Me.ListView1.Items.Add(Xitem.C1)
                lvitem.SubItems.AddRange(New String() {Xitem.C2})

            Next
        End If

    End Sub


    Private Function GetInfo() As Boolean
        Dim Completed As Boolean = False
        Dim MyExcel As New Excel.Application
        MyExcel.Workbooks.Open(Me.TextBox1.Text)

        'extract
        MyExcel.Sheets("sheet1").activate()
        MyExcel.Range("A1").Activate()

        Dim ThisRow As New ExcelRows

        Do
            If MyExcel.ActiveCell.Value > Nothing Or MyExcel.ActiveCell.Text > Nothing Then

                ThisRow.C1 = MyExcel.ActiveCell.Value
                MyExcel.ActiveCell.Offset(0, 1).Activate()
                ThisRow.C2 = MyExcel.ActiveCell.Value
                MyExcel.ActiveCell.Offset(0, 1).Activate()

                ExcelRowList.Add(ThisRow)
                MyExcel.ActiveCell.Offset(1, -2).Activate()

            Else
                Completed = True

                Exit Do
            End If
        Loop

        'close
        MyExcel.Workbooks.Close()
        MyExcel = Nothing

        Return Completed
    End Function

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim oIDW As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        'Dim oIDW As Inventor.Document

        For i = 0 To ListView1.Items.Count - 1
            'Do stuff
            MsgBox(ListView1.Items(i).ToString)
            MsgBox(ListView1.Items(i).SubItems(1).ToString)

            ' Find if the dwg exists.

            oIDW = oIDW.Documents.Open(ListView1.Items(i).ToString)
        Next

    End Sub
End Class

 

 

 

 

Regards

 

Andrew

 

0 Likes
190 Views
1 Reply
Reply (1)
Message 2 of 2

mfoster9TD82
Advocate
Advocate

I'm assuming you're talking about using this for an external .exe or an addin rather that an iLogic or macro.
With what you have there, you are looking for an open instance of Inventor with

Dim application as Inventor.Application = ...GetActiveObject("Inventor.Application")

that is your "ThisApplication" that you are used to using.
Then you'll also need to define a Document that you will open the file as with 

Dim document as Inventor.Document = application.Documents.Open(...)

From there is pretty much the same as iLogic.

 

There is more info about it in the API Overviews section in the Inventor API Help documentation included in the SDK tools