Connecting to inventor with Vb.net

Connecting to inventor with Vb.net

MechMachineMan
Advisor Advisor
2,677 Views
1 Reply
Message 1 of 2

Connecting to inventor with Vb.net

MechMachineMan
Advisor
Advisor

What am I doing wrong here/how do I get this properly working?

 

Imports Inventor
Imports System.Runtime.InteropServices

Public Class InventorApp
	Property oApp As Inventor.Application
	
	Public Shared Sub ConnectToInv()
    	Try
       		oApp =  Marshal.GetActiveObject("Inventor.Application")
    	Catch ex As Exception
        	MessageBox.Show("Cannot connect to Inventor")
        	Exit Sub
    	End Try
	End Sub
End Class

Sub Main()
	InventorApp.ConnectToInv
	Dim oDoc As Document
	oDoc = InventorApp.oApp.ActiveDocument
	
	MsgBox(oDoc.FullFileName)
	
	'Dim inputList As New List(Of String)

	
	'SortBOM(inputList)
End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Accepted solutions (1)
2,678 Views
1 Reply
Reply (1)
Message 2 of 2

MechMachineMan
Advisor
Advisor
Accepted solution

Guess I figured it out:

 

Imports System
Imports System.Type
Imports System.Activator
Imports Inventor
Imports System.Runtime.InteropServices

'Need to make this public so it can be used in other classes
Public Class CL_InventorApp
'Need to make this public so it can be used in other classes 'InventorInstance will be the accessible object within the 'CL_InventorApp class whenever we create access to the class Dim Public InventorInstance As Inventor.Application Dim _started As Boolean
'When you call New CL_InventorApp, this sub gets invoked. Public Sub New() 'Everything in this sub is fluff stolen from
'elsewhere with variable names changed to suit my purposes Try InventorInstance = Marshal.GetActiveObject("Inventor.Application") Catch ex As Exception Try Dim invAppType As Type = GetTypeFromProgID("Inventor.Application") InventorInstance = CreateInstance(invAppType) InventorInstance.Visible = True 'Note: if you shut down the Inventor session that was started 'this(way) there Is still an Inventor.exe running. We will use 'this Boolean to test whether or not the Inventor App will 'need to be shut down. _started = True Catch ex2 As Exception MsgBox(ex2.ToString()) MsgBox("Unable to get or start Inventor") Exit Sub End Try End Try End Sub End Class Public Sub Main() 'Need to create access to the class the app was opened in, so ref ' the CL_InventorApp. oInv_App is what we use to access that class. Dim oInv_App As New CL_InventorApp MsgBox("All is good") MsgBox(oInv_App.InventorInstance.ActiveDocument.FullFileName) End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes