Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CreateInstance is not loading Vault add-in

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
JamieVJohnson2
485 Views, 3 Replies

CreateInstance is not loading Vault add-in

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,

jvj
3 REPLIES 3
Message 2 of 4

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
Message 3 of 4

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.

jvj
Message 4 of 4

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.

 

jvj

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report