Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
TA.Fehr
in reply to: TA.Fehr

Hate to resurrect an old thread, but I've literally been searching for years, and no solution has yet been posted to this question.

 

The solution lies in keeping the addhandler active until the correct tab has been initiated.

The sample provided removes the handler as soon as the first ribbon is activated (ZeroDoc) however, as this isn't the tab desired, we need to keep the handler open until that tab is created.

 

Below is an example where an event is raised whenever the "Tools" tab is activated in the "Drawing" and "Assembly" environments.

 

It may be necessary, depending on the application, to include a "deactivate" event as well.

For good measure in my add-in I also included an event to "OnActivateDocument" from the ApplicationEvents properties inherent inside the Inventor Application. That way if someone switches between documents, the event will still fire even if the "Tools" tab is already activated.

 

Hope this helps anyone who runs into this problem in the future.

 

        Dim AddhandlerDrawing As Boolean = False
        Dim addhandlerAssembly As Boolean = false

 

 

 

        Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
                AddHandler Autodesk.Windows.ComponentManager.ItemInitialized, AddressOf Me.ComponentManager_ItemInitialized
        End Sub
 Private Sub ComponentManager_ItemInitialized(ByVal sender As Object, ByVal e As RibbonItemEventArgs)
            'now one Ribbon item is initialized, but the Ribbon control
            'may not be available yet, so check before
            If (Not (Autodesk.Windows.ComponentManager.Ribbon) Is Nothing) Then
                If ComponentManager.Ribbon.ToString = "Drawing"  Then
                    For Each Tab As Autodesk.Windows.RibbonTab In Autodesk.Windows.ComponentManager.Ribbon.Tabs
                        If (Tab.Id = "id_TabTools") Then
                            AddHandler Tab.Activated, AddressOf Me.Tab_Activated
                            AddhandlerDrawing = true
                        End If                        
                    Next
                    'and remove the event handler
                    
                Else if componentmanager.ribbon.tostring = "Assembly" then
                     For Each Tab As Autodesk.Windows.RibbonTab In Autodesk.Windows.ComponentManager.Ribbon.Tabs
                        If (Tab.Id = "id_TabTools") Then
                            AddHandler Tab.Activated, AddressOf Me.Tab_Activated
                            addhandlerAssembly = true
                        End If
                        
                    Next
                End If
               if addhandlerdrawing = True AndAlso
                        addhandlerAssembly = True Then RemoveHandler ComponentManager.ItemInitialized, AddressOf Me.ComponentManager_ItemInitialized
                
            End If

        End Sub

 

        Private Sub Tab_Activated(ByVal sender As Object, ByVal e As EventArgs)
           msgbox("Tab activated")
        End Sub