If you’ve gone through the lessons in the book I suggested earlier, or any of the online Microsoft tutorials that are available you should be familiar with what projects are and how to create them. I won’t go into a lot of detail but will go through the steps below.
Here are the steps to creating an exe program that will access and control Inventor using the API.
- After running Visual Basic 2010 Express, select the “New Project…” option, which is outlined in red below.
- In the New Project dialog select “Windows Forms Application” as the type of project and enter “DrawShape” for the project name.
- The project you’ve just created is a standard Windows application and doesn’t have any knowledge about Inventor’s API. In order to access Inventor’s API you need to make your project aware of the API and what it supports. You do this by referencing Inventor’s Interop library. The interop completely describes the API in a .Net friendly way.
To add the reference choose the “Add Reference…” command from the Project menu, as shown below.
In the Add Reference dialog choose the Browse tab and browse to the directory below (for whatever version of Inventor you’re using).
C:\Program Files\Autodesk\Inventor 2013\bin\Public Assemblies
Select “Autodesk.Inventor.Interop.dll”, as shown below and click OK.
You can view the references a project has by using the Project window and selecting the “Show All Files” button highlighted in red below. All of the references will be displayed in the “References” folder.
- I’ll talk more about this in my next post, but just so we end this post with your program doing something somewhat useful, add a button to your form, (I called mine btnRun), and add the code below into the Click event of the button. (Sorry about the weird line continuations but the width of a line in this blog interface is very limited.)
' Connect to a running instance of Inventor.
Dim invApp As Inventor.Application
invApp = _
Catch ex As Exception
MessageBox.Show("Inventor must be running.")
' Create a new part document.
Dim partDoc As Inventor.PartDocument
partDoc = invApp.Documents.Add( _
Now when you run your application and click the button the program will connect to Inventor if it’s running or display a warning message if it’s not. If it is running it will create a new part document. Each time you click the button a new part will be created. In the next post we’ll look at this code in more detail and discuss the basics of working with documents.