Keep Your Interop Up to Date

I just finished working with a customer that was having a problem accessing certain functionality in the API.  He had written an initial prototype in VBA that worked as expected but then when he started to convert the program to .Net some of the Inventor API objects he was using weren’t available.  The reason is that he was using an old .Net interop.

The Inventor API is exposed using Microsoft’s COM technology.  The contents of the API (it’s objects, methods, properties, and events) are described in a file known as a type library.  When you use VBA it directly references this type library to know what’s in Inventor’s API and uses this to support Intellisense and to be able to compile and run the program.  VB.Net and C# are .Net based languages and don’t support directly calling a COM API.  To provide support for COM API’s .Net supports the creation of an interop library that serves as a translation layer between COM and .Net. The Interop provides the same functionality to VB.Net or C# that the type library does to VBA.  It describes all of the objects and functions in the Inventor API and converts the .Net API call into a native COM call.  As of the last few .Net releases this technology works very good and in almost all cases makes it completely transparent that you’re not working directly with the COM API.

When you create a new .Net or C# program to work with Inventor you need to add a reference to Inventor’s COM interop in order to have access to the API.  You do this by using the References command in Visual Studio.  In the dialog, use the “Browse” option to the left and then click the “Browse…” button at the bottom of the dialog.

InteropAddReference 

Browse to “C:\Programs Files\Autodesk\Inventor XXXX\Bin\Public Assemblies”, (where XXXX is the version of Inventor you want to use) and select “autodesk.inventor.interop.dll”.

InteropPickAssembly

 

Your program is now dependent on the interop for that version of Inventor.  Let’s say that you create a reference to Inventor 2014 and then later you uninstall Inventor and install Inventor 2015.  The API is backward compatible so when you installed Inventor 2015 it installed the interop for 2015 but also installed interops for several previous versions so programs dependent on those older version will still continue to work.  But it your program needs to use some functionality that is new in Inventor 2015 you need to change the reference to the newer interop where this new functionality is defined.

You can see what references an existing program has in the Solution Explorer in Visual Studio.  By default they’re not shown but by clicking the “Show All Files” button a new “References” folder will appear in the tree, as shown below.

InteropShowReferences

 

You can see more information about a specific reference by selecting it and looking in the Properties window, as shown below.  In this case I’ve selected the “autodesk.inventor.interop” and it’s showing me that it’s version 19.0.0.0.

InteropShowVersion

 

The version numbers are confusing because they don’t directly correlate with the public version of Inventor.  Here’s a table showing the public version, the corresponding software version, and the internal development name.

Public Version Software Version Internal Name
2011 15 Sikorsky
2012 16 Brunel
2013 17 Goodyear
2014 18 Franklin
2015 19 Dyson
2016 20 Shelby
2017 21 Enzo
2018 22 Elon
2019 23 Zora

-Brian


Comments

4 responses to “Keep Your Interop Up to Date”

  1. Thanks Brian,
    Your the master!! It’s working now :-)

  2. Katie Miller Avatar
    Katie Miller

    I would like to know what the difference is between linking to the interop under Program files or the interop under C:\Windows\Microsoft.NET..... etc.. and should we use one over the other?

  3. The interops in the GAC (C:\Windows\Microsft.NET\Assembly...) are intended to be private and you should always reference the one in the “Inventor\Public Assemblies” directory. Previously, Visual Studio wouldn’t allow you to directly reference interops in the GAC but it doesn’t block it anymore. When you reference a primary interop outside the GAC but it also exists in the GAC, .NET is able to find the one in the GAC and use it. So for example, let’s say you create a program using Inventor 2015 and reference the interop in its “Public Assemblies” folder. Then someone uses that program on a machine that only has Inventor 2016. You’re program will still work because .NET finds the 2015 version in the GAC and uses it. Inventor installs several version of the primary interop into the GAC to support programs written against older versions of Inventor.

  4. Katie Miller Avatar
    Katie Miller

    Awesome! Thanks for the Guidance! Always great chatting with you!

Leave a Reply to David TruyensCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading