Some code:
Dim invAppType As Type = GetTypeFromProgID("Inventor.Application") invApp = CreateInstance(invAppType)
More than 90 percent of the time, when this code is run, Inventor opens, but ALL the add-in's are not loaded. I don't have ANY custom add-ins they all came out of the box. My biggest issue is when it does not load the Vault Add-in. Is there a better way? A way to ensure Inventor loads properly with all add-in's during API usage.
If the user opens Inventor first it loads all the add-ins as expected. Then I can use:
invApp = Marshal.GetActiveObject("Inventor.Application")
To grab that Inventor, but my stand alone program doesn't always have that luxury.
Please help,
Solved! Go to Solution.
Solved by JamieVJohnson2. Go to Solution.
Check here: http://modthemachine.typepad.com/my_weblog/2013/02/inventor-api-training-lesson-1.html under "How to access the Application Object?" which looks like a slightly different approach from what you're using as well as more information than the API help.
Excerpt:
Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application") m_inventorApp = System.Activator.CreateInstance(inventorAppType) 'Must be set visible explicitly m_inventorApp.Visible = True
Nope, nothing new there, he is doing the exact same thing as me. In fact it looks like my original code is in his blog.
I settled on a work around, all be it brute force:
Try invApp = Marshal.GetActiveObject("Inventor.Application") Catch ex As Exception Try Dim invAppType As Type = GetTypeFromProgID("Inventor.Application") invApp = CreateInstance(invAppType) For Each addIn As ApplicationAddIn In invApp.ApplicationAddIns Try If addIn.LoadBehavior = AddInLoadBehaviorEnum.kLoadImmediately Then addIn.Activate() End If Catch exAddIn As Exception 'skip it End Try Next invApp.Visible = True invAppWasStarted = True Catch ex2 As Exception MsgBox("Unable to get or start Inventor" & vbCr & ex2.ToString, MsgBoxStyle.SystemModal) End Try End Try End If Try Dim dcountTest As Integer = invApp.Documents.Count Catch ex As Exception invApp = Nothing GetInventorApplication() End Try Return invApp
After a successful attempt to create Inventor application, and carefully wrapped in a try catch block for each add-in I run the .Activate command on the ones expected to start Automatically. This code does give strange results when there are several inventor apps running, probably because a few of them are not visible, but its better than nothing. The document count at the end is a test to see if the program is holding on to an instance of Inventor that has been closed (or crashed). It will throw an error on documents.count if it is not fully functional. Forces the program to dump that instance and try again.