This posts illustrates how to connect an Inventor addin from an external executable and invoke a method through the COM server that will be performed in-process by the addin.
The Addin must return the AddinServer class intance through the Automation property:
Public ReadOnly Property Automation() As Object _
Implements Inventor.ApplicationAddInServer.Automation
Get
Return Me
End Get
End Property
-
It should also provides and implement an Interface, in this case we use a simple interface with a single method to implement:
Public Interface DemoInterface
Sub DemoMethod(str As String)
End Interface
<ProgIdAttribute("DemoVbAddIn.StandardAddInServer"), _
GuidAttribute("7ce7b998-b41b-4ff5-b62b-19e73fc5ec7b")> _
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
Implements DemoInterface
' ApplicationAddInServer implementation here...
Public Sub demoMethod(Str As String) _
Implements DemoInterface.DemoMethod
MsgBox(Str)
End Sub
End Class
On the exe side, you need to access the addin, using the GUID is the most reliable way, then obtain this interface:
Private Sub Form1_Load(
ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles Me.Load
Try
Dim InvApp As Inventor.Application =
System.Runtime.InteropServices.Marshal.GetActiveObject( _
"Inventor.Application")
Try
Dim addIn As Inventor.ApplicationAddIn =
InvApp.ApplicationAddIns.ItemById( _
"{7ce7b998-b41b-4ff5-b62b-19e73fc5ec7b}")
_addInInterface = addIn.Automation
Catch ex As Exception
System.Windows.Forms.MessageBox.Show( _
"Error: AddIn not found...")
Button1.Enabled = False
Exit Sub
End Try
Catch ex As Exception
System.Windows.Forms.MessageBox.Show( _
"Error: Inventor must be running...")
Button1.Enabled = False
Exit Sub
End Try
End Sub