Hi,
I am using Inventor 2010 Professional, and Visual Studio 2010 professional to develop addin. The addin is an registered addin. For a long long time, the addin works perfectly. But 3 days ago, it suddenly did not work! It fails to go through code line: thisapplication = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application").
Using the exact code, I re-compile the addin,and unregister then register it again, and exhaust any other method I can think of, but the problem consists!
There are similar cases in forum as follows, but it provides no help either.
I also disable the UAC, the problem persists.
Attached is my test code and error message for my case.
Please help!
Thanks
Limin
Solved! Go to Solution.
Solved by liminma8458. Go to Solution.
The similar case in the forum is http://forums.autodesk.com/t5/Inventor-Customization/Marshal-GetActiveObject-quot-Inventor-Applicati...
Looks like the application object can NOT be passed to the AddIn when the AddIn is loaded by Inventor. Why?
If this is being loaded as an Addin by Inventor there should be a file/class called StandardAddInServer.vb. In this file there is an activate method. This is where Inventor passes in an instance of the Inventor Application for use.
Namespace Sample <ProgIdAttribute("Sample.StandardAddInServer"), _ GuidAttribute("0xxxxxx5-9xx2-4xx9-9xxa-3xxxxxdcxxxxx")> _ Public Class StandardAddInServer Implements Inventor.ApplicationAddInServer ' Inventor application object. Private thisapplication As Inventor.Application Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, _ ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate ' This method is called by Inventor when it loads the AddIn. ' The AddInSiteObject provides access to the Inventor Application object. ' The FirstTime flag indicates if the AddIn is loaded for the first time. ' Initialize AddIn members. thisapplication = addInSiteObject.Application End Sub End Class End Namespace
Form there you can pass it to where you need.
rjay75:
Yes. If this this a registered addin, we can pass the inventor application object through "StandardAddInServer" by thisapplication = addInSiteObject.Application. This is one of ways.
But, we have to use [thisapplication = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")] to connect Inventor in other classes or even in another DLL file which is not even registered. And it has been used by most Inventor tutorials and it has been working well.
So the question is why [GetActiveObject("Inventor.Application")] does not work suddenly. How to make it works again? Otherwise, we have to modify all our code by make "thisapplication" transfer as an argument.
Thanks
It works now! But I am so puzzled! The only thing I do is that I opened Inventor 2011 (I have both 2011 and 2013 in my computer), the addin went through Inventor 2011. Then I opened Inventor 2013, It worked again. I don't know why!!!
I'm glad your app works again... If you have an add-in, you should use the Inventor.Application reference that has been passed to the Activate method, as Thomas pointed out. If you have an external application that connects to Inventor, then you should use GetActiveObject. This method may fail if Inventor is not regsitered properly in the registry or your install has been corrupted. When you started 2013, it may have regsitered the entry correctly, so you got it fixed.
If you are using an extra dll not registered (this is an unusual workflow), I would suggest you expose a method in that dll that allows you to pass the Inventor.Application object from the add-in to the dll, and store it as reference inside the side dll. Using GetActiveObject might be risky in the way a user may have multiple instances of Inventor open at the same time and you don't have a way to select which one is returned by GetActiveObject.
Regards,
Philippe.
Thanks, Phil.
We only allow one Inventor instance running when running our addin program.
A registered addin works as a starting point in our program. It has many its own classes and modules which use GetActiveObject to connect Inventor. Also, the registerd addin call functions from extra DLLs (non-registered) which also use GetActiveObject to connect Inventor. The way of linking Inventor instance worked fine all the time before this failure happened.
This time looks like the Inventor fixed the register issue itself by switching to Inventor 2011 then back into Inventor 2013. But this is a unusal ans desparated way.
So, if this failure happens next time, how to fix the register entry issue in a step by step routing method? Can I fix that in the register list by using Regedit?
Thanks again
I have no idea how you would need to proceed manually with the registry... messing up with registry settings can have nasty consequences. I would stick with my previous suggestion, I don't see any technical limitation with passing a single instance of Inventor through any dll that may need it, you would need to rewrite your code and review your approach obviously but I don't have a cleaner suggestion at the moment.
Regards,
Philippe.
to andrenaulfal:
yes, I have Inventor 2011 and Inventor 2013 in the same machine. Is it the reason fo the problem?
When Marshal.GetActiveObject() is called it is expecting a progId. This ID is set in a table that is managed by Windows. With multiple versions of Inventor on a machine this ID can be reset to either version of Inventor or even cleared. The only way I've found to reset the ProgId when it's not cooperating is to make sure all Inventor instances are closed. Open the the latest version. It may ask to reregister components, answer yes.(Sometimes I have to open and close an older version first.)
Yes. In my case, to reset ID to newer version (Inventor 2013), I have to open and close an older version (Inventor 2011) first, then open the newer version
successfully.
Thanks