This is a follow-up of my tutorial: "Creating an Inventor Addin". Writing code usually involves a lot of testing. In the case of writing addins this can become a pain. Each time you want to test your addon you need to restart Inventor and maybe open a document.

Luckily for us, there is a loophole. We can create a small application that picks up the Inventor object. With that, we can initialize our class that does the real work in the addin. In this case that is the “ThisRule” class. So the application can emulate clicking the button. That means that you can keep running Inventor and maybe keep documents open.  While still being able to test your code.

If you have a lot of actions that you would like the test then you don’t need to create multiple applications. I would suggest that you create 1 application with a form and some buttons for the actions that you want to test. However, this is not a part of this tutorial.

The application

Add an extra application to your project. In my case, I’m going for a console application. (If you want to create a form with buttons you need to select an appropriate project for that.)

 

Make sure that you pick a .Net Framework project.

Give the project a name. I will go with “MyDebugApp”.

Add the following reference to the new project (like we did in the addin project):

C:\Program Files\Autodesk\Inventor [VERSION]\Bin\Public Assemblies\Autodesk.Inventor.Interop.dll

Also, add a reference to the addin project. Make sure you have selected the new project in the “Solution Explorer”

The starter Module (Class)

In new console applications, there is usually only 1 Module/class. By default, there is only 1 sub/function in there. This is the class that gets called when you start your application. That is also where we need to put our code. In my case, it’s called “Module1”. Change the code to look like this. (Do not change the name of the module/class unless you are also going to change the startup module/class in your project settings)

Imports Inventor
Imports System.Runtime.InteropServices
Imports MyILogicAddin ' This is the namespace from the addin dll!

Module Module1

    Sub Main()

        Dim inventorObject As Inventor.Application = Marshal.GetActiveObject("Inventor.Application")
        MyButton_OnExecute(inventorObject)

    End Sub

    Private Sub MyButton_OnExecute(_inventor As Inventor.Application)

        Try

            Dim rule As New ThisRule()
            rule.ThisApplication = _inventor
            rule.Main()

        Catch ex As Exception

            MsgBox("Something went wrong while runing rule. Message: " & ex.Message)

        End Try
    End Sub

End Module

 Notice that I used the namespace in the line where we declare the “rule” variable. Also, notice that the code in the function MyButton.MyButton_OnExecute(...) is very similar to the function Module1.MyButton_OnExecute(...).   

Running the test app

At this point, all is set but when you hit run (F5) then Inventor starts. Not exactly what we need. Remember we want to have Inventor running and start our little app. You need to set the new app as the start-up app. You can do that like this: In your "solution explore" right-click the project and select “Set as Startup Project”.

 Now you can press “Run”.

One side note. There is a disadvantage to running your code like this, it’s noticeable slower than running code as an addin. But start running the code is much faster.

 

 

Skills:

Autodesk Inventor, Vault, Git, C#, vb, .net, php HTML, css, js

Education:

University computer science.
HBO Mechanical engineer.
MBO Fine mechanics.

Experience:

Programmer and Mechanical engineer at Kelvion
(2016 - 20..)

Mechanical engineer at Strukton
(2009 - 2016)

Mechanical engineer at RDG-engineering
(2007 - 2009)

CNC Programmer at VMC
(2005 - 2007)

volunteer at Taizé
(2007)

Certifications:

Objectgeoriënteerd analyseren en ontwerpen, Objectgeoriënteerd programmeren in Java, Webapplicaties: de clientkant, Databases, Security Aware Programmer, Web Security Specialist