Placing Add-In button to a custom ribbon panel spoils Add-In un-load-ability

Placing Add-In button to a custom ribbon panel spoils Add-In un-load-ability

Maxim-CADman77
Advisor Advisor
362 Views
5 Replies
Message 1 of 6

Placing Add-In button to a custom ribbon panel spoils Add-In un-load-ability

Maxim-CADman77
Advisor
Advisor

Recently I've decided that my Add-In button worth to be placed on a separate (custom) ribbon panel.
To get this I've changed the ribbon panel defining line in the AddButtonDefinitionToRibbon Sub:

Private Sub AddButtonDefinitionToRibbon()
	Dim ribbon As Ribbon = _inventor.UserInterfaceManager.Ribbons.Item("Part")
	Dim ribbonTab As RibbonTab = ribbon.RibbonTabs.Item("id_TabManage")
	Dim ribbonPanel As RibbonPanel
	
	'ribbonPanel = ribbonTab.RibbonPanels.Item("iLogic.RibbonPanel") ' <= INITIAL VERSION (OK)
	
	ribbonPanel = ribbonTab.RibbonPanels.Add("My Panel", "My_Panel", "{<My_AddIn_ClientId>}") ' <= NEW VERSION (unloadable)
	
	_control = ribbonPanel.CommandControls.AddButton(_settingsButton)
End Sub

I got almost the expected except the add-in now can't be truly unloaded using Add-In Manager ("My panel" disappears but current status in Add-In Manager kept "Loaded").

 

What I'm missing?

Please vote for Inventor-Idea Text Search within Option Names

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

Michael.Navara
Advisor
Advisor

Usually this occurs when some exception is thrown form Deactivate method of add-in

0 Likes
Message 3 of 6

Maxim-CADman77
Advisor
Advisor

There is no any Exceptions (at least no any messages neither on load nor on unload)

Current deactivate sub (inside StandardAddInServer.vb) is:

 

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

 

PS: I want to highlight it one more time: Changing just one line of code makes add-in un-loadable.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 6

CattabianiI
Collaborator
Collaborator
Accepted solution

Wrap the Deactivate in a try catch:

    Public Sub Deactivate() Implements ApplicationAddInServer.Deactivate
        Try
          _myButton.Unload()
          _myButton = Nothing
        Catch ex As Exception
          MsgBox(ex.ToString())
        End Try
    End Sub

And also: what is _myButton? CommandControl does not have an Unload method. Just a Delete one.

0 Likes
Message 5 of 6

Maxim-CADman77
Advisor
Advisor

Wow, I was not aware Exceptions are muted.

My fault was in those two (commented below) lines within MyButton Class:

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

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 6

CattabianiI
Collaborator
Collaborator

Exception are not muted or unmuted, 🙂 is that you usually have someone that handle them showing them to you. For example in event handlers you should always handle exception: https://stackoverflow.com/questions/8744480/exception-management-practices-inside-event-handlers

0 Likes