Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Maxim-CADman77
497 Views, 10 Replies

Exception 80004005 on Add-In load

Recently I've created my first ever Inventor Add-In based on iLogic Rule (many thanks to @JelteDeJong  for article Creating an Inventor Addin).

My Add-In works as expected except one thing - upon initialization (load) it generates message:

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

Any ideas on how to workaround this?

Please vote for Inventor-Idea Text Search within Option Names

jjstr8
in reply to: Maxim-CADman77

What is the line of code is the exception being thrown on?

Maxim-CADman77
in reply to: jjstr8

@jjstr8 

Exception occurs in button class (please don't laugh loud on my debug MsgBox-es):

 

 

 

 

Imports Inventor
Public Class MyButton

    Private _inventor As Application
    Private _settingsButton As ButtonDefinition
    Public Sub New(inventor As Application)
        MsgBox("00")
        _inventor = inventor
        MsgBox("10")
        SetupButtonDefinition()
        MsgBox("20")
        AddButtonDefinitionToRibbon()
        MsgBox("30")
    End Sub

    Private Sub SetupButtonDefinition()

        MsgBox("11")
        Dim conDefs As ControlDefinitions = _inventor.CommandManager.ControlDefinitions
        _settingsButton = conDefs.AddButtonDefinition(
            "CJS Cutter",
            "CJSC_VB",
            CommandTypesEnum.kEditMaskCmdType,
            Guid.NewGuid().ToString(),
            "Automatic creation of halved-style paired slots for overlapping perpendicular flat bodies of Multi-Body Part.",
            "Cross-Joint Slot Cutter (VB)")
        MsgBox("12")
        AddHandler _settingsButton.OnExecute, AddressOf MyButton_OnExecute
        MsgBox("13")
        _settingsButton.StandardIcon = PictureDispConverter.ToIPictureDisp(My.Resources.CJSC_icon_16)
        MsgBox("14")
        _settingsButton.LargeIcon = PictureDispConverter.ToIPictureDisp(My.Resources.CJSC_icon_32)
        MsgBox("15")

    End Sub

    Private Sub AddButtonDefinitionToRibbon()

        MsgBox("21")
        Dim ribbon As Ribbon = _inventor.UserInterfaceManager.Ribbons.Item("Part")
        MsgBox("22")
        Dim ribbonTab As RibbonTab = ribbon.RibbonTabs.Item("id_TabModel")
        MsgBox("23")
        Dim ribbonPanel As RibbonPanel = ribbonTab.RibbonPanels.Item("Part.id_TabModel.UserCommands")
        MsgBox("24")
        ribbonPanel.CommandControls.AddButton(_settingsButton)
        MsgBox("25")

    End Sub

    Private Sub MyButton_OnExecute(Context As NameValueMap)

        Try
            Dim rule As New ThisRule()
            rule.ThisApplication = _inventor
            rule.Main()
        Catch ex As Exception
            MsgBox("Something went wrong while running rule. Message: " & ex.Message)
        End Try

    End Sub

End Class

 

 

 

 

... but it seems there are two different cases:

 

Case #1 (SOLVED). If the Add-In is loading with "Load Automatically" option then exception occurs on:


ribbonPanel.CommandControls.AddButton(_settingsButton)

 

 

Case #2. If Add-In is loading manually from Add-In Manager then exception occurs on:

 

_settingsButton = conDefs.AddButtonDefinition( ...

 

... and it seems not related to my values (reproducible on the code from the article)

Please vote for Inventor-Idea Text Search within Option Names

The walk-through of building the add-in step-by-step on his blog is really informative.

 

Here are a few more tools to help with your add-in development. These along with what you have created above will allow you to compare which features & layouts you like best. These will also then be available within Visual Studio as templates to start your project with.

 

Autodesk provides a number of samples within your Inventor install. It just requires running the installer to download those files. Within the Autodesk Inventor 20** SDK, install the Developer Tools. It will probably be in a location like:
C:\Users\Public\Documents\Autodesk\Inventor 2022\SDK

 

Brian Ekins also provides a simplified setup for an add-in template:
https://ekinssolutions.com/nifty_addin_template/

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.

_

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.

The exception code doesn't tell me much. But most of the time if I run into trouble it has to do with the icons. You could try to run the code without loading the icons. Just to make sure they are not the problem. In your code that would mean removing the following lines:

        MsgBox("12")
        AddHandler _settingsButton.OnExecute, AddressOf MyButton_OnExecute
        MsgBox("13")
        _settingsButton.StandardIcon = PictureDispConverter.ToIPictureDisp(My.Resources.CJSC_icon_16)
        MsgBox("14")
        _settingsButton.LargeIcon = PictureDispConverter.ToIPictureDisp(My.Resources.CJSC_icon_32)
        MsgBox("15")

(line 27 to 33)

If the addin the addin loads without those lines you know the icons are the problem. In that case, you could try using my images (https://github.com/hjalte79/MyILogicAddin/tree/master/MyILogicAddin/Recources) as a test.

 

Just another tip: Instead of using the msg boxes you could add breakpoints to your and step through the code. Have a look here: https://learn.microsoft.com/en-us/visualstudio/debugger/debugger-feature-tour?view=vs-2022

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

I believe managed to pin first case to "User Commands" Panel ("Part.id_TabModel.UserCommands")

This panel I believe is a new feature of 2023 (iLogic Rules as Buttons) it's Id/Name differs from all the rest (the only one containing two dots). Maybe this panel is not completely support placing add-in buttons (even so add-in button appear on it and works ok).

Please vote for Inventor-Idea Text Search within Option Names

jjstr8
in reply to: Maxim-CADman77

@Maxim-CADman77   I couldn't add it to the User Commands panel in version 2019.  It adds fine to another panel.  It looks like that panel is only meant to work with Customize User Commands.  It's strange that it still adds the button, but you can't see it in the list when you do Customize User Commands.

Maxim-CADman77
in reply to: jjstr8

@jjstr8 

May I kindly ask you try to reproduce Case 2 on your 2019 config with Button Class code from the above-mentioned article?

Imports Inventor
Public Class MyButton
    Private _inventor As Inventor.Application
    Private _settingsButton As ButtonDefinition
    Public Sub New(inventor As Inventor.Application)
        _inventor = inventor

        SetupButtonDefinition()
        AddButtonDefinitionToRibbon()
    End Sub

    Private Sub SetupButtonDefinition()

        Dim conDefs As ControlDefinitions = _inventor.CommandManager.ControlDefinitions
        _settingsButton = conDefs.AddButtonDefinition(
            "MyButton DisplayName",
            "MyButton InternalName",
            CommandTypesEnum.kEditMaskCmdType,
            Guid.NewGuid().ToString(),
            "MyButton DescriptionText",
            "MyButton ToolTipText")
        AddHandler _settingsButton.OnExecute, AddressOf MyButton_OnExecute

    End Sub

    Private Sub AddButtonDefinitionToRibbon()

        Dim ribbon As Ribbon = _inventor.UserInterfaceManager.Ribbons.Item("Assembly")
        Dim ribbonTab As RibbonTab = ribbon.RibbonTabs.Item("id_TabManage")
        Dim ribbonPanel As RibbonPanel = ribbonTab.RibbonPanels.Item("iLogic.RibbonPanel")
        ribbonPanel.CommandControls.AddButton(_settingsButton)

    End Sub

    Private Sub MyButton_OnExecute(Context As NameValueMap)

        Try

            Dim rule As New ThisRule()
            rule.ThisApplication = _inventor
            rule.Main()

        Catch ex As Exception

            MsgBox("Something went wrong while runing rule. Message: " & ex.Message)

        End Try
    End Sub
End Class

 

Please vote for Inventor-Idea Text Search within Option Names

Dear @JelteDeJong 
Could you, please, confirm (and comment) exception 80004005 on each (except the first within current Inventor session) attempt to load Add-In with line:

 

 

        _settingsButton = conDefs.AddButtonDefinition(
            "MyButton DisplayName",
            "MyButton InternalName",
            CommandTypesEnum.kEditMaskCmdType,
            Guid.NewGuid().ToString(),
            "MyButton DescriptionText",
            "MyButton ToolTipText")

 

 

I believe the issue could be fixed with wrapping the line into Try-Catch, but I don't understand what should go after "Catch" (for sure not just "End Try").

Please vote for Inventor-Idea Text Search within Option Names

At first, I could not replicate the error. But I think I found the problem. The devil seems to be in the details. I could reproduce the problem with the following steps:

  • Start Inventor.
  • Load the addin with the add-in manager.
    • Notice that the addin loads as expected!
  • Unload the addin with the add-in manager.
    • Notice that the addin is not really unloaded. The button is still on the ribbon and still works.
  • Load the addin with the add-in manager.
    • Now we get the exception!

The problem is that the ButtonDefinition and CommandControl are not unloaded and therefore they can't be recreated. For normal users, this should not be a problem because they rarely reload addins. And I don't know what your use case is but you can solve the problem by unloading the ButtonDefinition and CommandControl explicitly on deactivation of the addin.

Cahnge the StandardAddInServer.Deactivate() to look like this:

 

Public Sub Deactivate() Implements ApplicationAddInServer.Deactivate
    _myButton.Unload()
    _myButton = Nothing
End Sub

 

 And your class MyButton should look like this.

 

Imports Inventor
Public Class MyButton
    Private _inventor As Inventor.Application
    Private _settingsButton As ButtonDefinition
    Private _control As CommandControl
    Public Sub New(inventor As Inventor.Application)
        _inventor = inventor

        SetupButtonDefinition()
        AddButtonDefinitionToRibbon()
    End Sub

    Public Sub Unload()
        _control.Delete()
        _control = Nothing
        _settingsButton.Delete()
        _settingsButton = Nothing
    End Sub

    Private Sub SetupButtonDefinition()

        Dim conDefs As ControlDefinitions = _inventor.CommandManager.ControlDefinitions
        _settingsButton = conDefs.AddButtonDefinition(
            "MyButton DisplayName",
            "MyButton InternalName",
            CommandTypesEnum.kEditMaskCmdType,
            Guid.NewGuid().ToString(),
            "MyButton DescriptionText",
            "MyButton ToolTipText",)

        AddHandler _settingsButton.OnExecute, AddressOf MyButton_OnExecute

        _settingsButton.StandardIcon = PictureDispConverter.ToIPictureDisp(My.Resources.MyImage16x16)
        _settingsButton.LargeIcon = PictureDispConverter.ToIPictureDisp(My.Resources.MyImage32x32)
    End Sub

    Private Sub AddButtonDefinitionToRibbon()

        Dim ribbon As Ribbon = _inventor.UserInterfaceManager.Ribbons.Item("Assembly")
        Dim ribbonTab As RibbonTab = ribbon.RibbonTabs.Item("id_TabManage")
        Dim ribbonPanel As RibbonPanel = ribbonTab.RibbonPanels.Item("iLogic.RibbonPanel")
        _control = ribbonPanel.CommandControls.AddButton(_settingsButton)

    End Sub

    Private Sub MyButton_OnExecute(Context As NameValueMap)

        Try

            Dim rule As New ThisRule()
            rule.ThisApplication = _inventor
            rule.Main()

        Catch ex As Exception

            MsgBox("Something went wrong while runing rule. Message: " & ex.Message)

        End Try

    End Sub

End Class

 

you can view the changes here:

https://github.com/hjalte79/MyILogicAddin/commit/6b566804dbe8ae50048f85f92b968192705245d8

 

 

 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com