Connecting an Inventor AddIn from an external application (VB.NET)

By Philippe Leefsma

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

 

     &#1
60;     
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

 


Comments

2 responses to “Connecting an Inventor AddIn from an external application (VB.NET)”

  1. Hello everyone!
    Im writting an addin for inventor 2014 and Im not sure how to make addin to disapear from the ribbon when user unchecks the unload checkbox in addin manager? and vice versa to appear when user check the box?
    Any help is appreciated.
    Thank you,
    Alex

  2. That question is unrelated to the topic of this post. Please open a new thread on the Inventor Customization forum:
    http://forums.autodesk.com/t5/Inventor-Customization/bd-p/120
    Thanks,
    Philippe.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading