How to handle Inventor not installed on "C" drive in my application

How to handle Inventor not installed on "C" drive in my application

ianteneth
Advocate Advocate
778 Views
5 Replies
Message 1 of 6

How to handle Inventor not installed on "C" drive in my application

ianteneth
Advocate
Advocate

I am writing my first desktop plugin in Visual Studio for Inventor which references the Autodesk.Inventor.Interop.dll file. This file is located in the installation folder for Inventor. And I just realized that it is possible for a user to install Inventor on a drive other than "C". Right now my reference to this dll is hard coded to point to the "C" drive.

 

Does anyone have any experience dealing with locating this dll file in their applications? Should I copy the Inventor interop dll to the user's computer as part of the installation so I know where it is? Does everyone just assume Inventor is installed on the "C" drive? Any thoughts are appreciated!

 

0 Likes
Accepted solutions (1)
779 Views
5 Replies
Replies (5)
Message 2 of 6

AlexFielder
Advisor
Advisor

Without seeing your solution files, I'm not even sure how it's possible to hard-code the path to the Inventor.Interop dll file.

 

Can you stick the solution in a zip file on here?

0 Likes
Message 3 of 6

ianteneth
Advocate
Advocate

Hi Alex. Thanks for the reply! I have attached a sample Visual Studio solution that demonstrates what I am talking about. Also, here are some screenshots also. This small program will just print the active document name. As you can see, I have referenced the Inventor Interop dll in the references for this project by browsing to the location of the dll.

 

Annotation 2020-04-13 162511.png

 

Annotation 2020-04-13 162601-2.png

 

0 Likes
Message 4 of 6

AlexFielder
Advisor
Advisor

It's an interesting conundrum for sure; do you have any control over where users are installing Inventor? Is this tool you're developing for your company in general?

 

You may be able to resolve the path to the inventor interop dll using Reflection like in this post:

https://stackoverflow.com/a/22120718/572634

 

// using System.Reflection and System.IO

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args )
{
    if (args.Name.ToUpper().StartsWith("XCEED.WPF"))
    {
       string asmLocation = Assembly.GetExecutingAssembly().Location;

       string asmName = args.Name.Substring(0, args.Name.IndexOf(','));
       string filename = Path.Combine( asmLocation, asmName );

       if (File.Exists(filename)) return Assembly.LoadFrom(filename);
    }
}

Whereupon the 'Assembly' in this case is the Inventor application itself

 

I would usually throw this in a converter to VB.NET but it wouldn't work today, hopefully you get the idea...?

0 Likes
Message 5 of 6

ianteneth
Advocate
Advocate

I appreciate the assistance. I will try out the reflection method as my tool will be available on the store and I cannot control where users install Inventor.

 

I have trouble though believing that currently released Inventor plugins don't also have this issue. Thanks again.

0 Likes
Message 6 of 6

tobias.orlow
Alumni
Alumni
Accepted solution

Hi @ianteneth ,

 

When installing Inventor, the interop.dll should also be put into a folder of the corresponding version under

"C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Autodesk.Inventor.Interop\", regardless of where Inventor gets installed.

You could reference your .dll from there.

 

Many thanks,

Tobias Orlow

Tobias Orlow
Designated Support Specialist
Customer Success Organization
Linkedin: www.linkedin.com/in/tobiasorlow/