help with code to create a new Ribbon Tab in Inventor

help with code to create a new Ribbon Tab in Inventor

Mild_Annoyance
Contributor Contributor
215 Views
2 Replies
Message 1 of 3

help with code to create a new Ribbon Tab in Inventor

Mild_Annoyance
Contributor
Contributor

So below is a code I have that was created in Visual Basic 2017 just trying to add a Ribbon Tab to Inventor 2024. In Visual Basic the code has not errors and everything is good. However when I go to open Inventor I get this error.

Screenshot 2025-03-07 101809.png

 

I hit ok and go to the Add-In Manager and the .addin file is set to load. The Ribbon Tab is not created in a part, assembly, or drawing file. Am I missing something in my code thats not properly creating the Ribbon Tab or is this an issue with Iventor? I appreciate any help.

 

Imports Inventor

Public Class WorkOrderAddIn
    Implements ApplicationAddInServer

    Private invApp As Inventor.Application

    ' Define your ClassId and ClientId here (use the same GUIDs as in your .addin file)
    Private Const ClassId As String = "{536B4E41-CBA6-4F44-AAAF-2F3438D66660}"
    Private Const ClientId As String = "{536B4E41-CBA6-4F44-AAAF-2F3438D66660}"

    Public Sub Activate(ApplicationAddInSite As ApplicationAddInSite, FirstTime As Boolean) Implements ApplicationAddInServer.Activate
        ' Initialize the Inventor application object
        invApp = ApplicationAddInSite.Application

        ' Now call OnStartup to handle ribbon creation
        OnStartup()
    End Sub

    ' The OnStartup method ensures that ribbon tab is added only after Inventor is fully initialized
    Public Sub OnStartup()
        Try
            ' Ensure Inventor is initialized
            If invApp IsNot Nothing Then
                ' Handle the tab creation process here
                Dim uiMgr As UserInterfaceManager = invApp.UserInterfaceManager

                ' Check if the tab already exists to prevent duplicates
                Dim awiTab As RibbonTab = Nothing
                Try
                    awiTab = uiMgr.Ribbons.Item("Part").RibbonTabs.Item("AWI_Tools_Tab") ' Test with "Part" ribbon context
                Catch ex As Exception
                    ' The tab does not exist, so we'll create it
                    MsgBox("Tab does not exist, creating a new one.")
                End Try

                If awiTab Is Nothing Then
                    ' Create new Ribbon Tab (Visible in all file types)
                    awiTab = uiMgr.Ribbons.Item("Part").RibbonTabs.Add("AWI Tools", "AWI_Tools_Tab", "Part", True)
                    MsgBox("Ribbon tab created successfully.")
                End If
            End If
        Catch ex As Exception
            ' Handle any potential errors
            MsgBox("Error during startup: " & ex.Message)
        End Try
    End Sub

    ' Deactivate method is used for cleanup when the Add-In is unloaded
    Public Sub Deactivate() Implements ApplicationAddInServer.Deactivate
        ' Cleanup code (if needed)
    End Sub

    Public ReadOnly Property Automation As Object Implements ApplicationAddInServer.Automation
        Get
            Return Nothing
        End Get
    End Property

    Public Sub ExecuteCommand(CommandID As Integer) Implements ApplicationAddInServer.ExecuteCommand
        ' Required but not used
    End Sub
End Class
0 Likes
216 Views
2 Replies
Replies (2)
Message 2 of 3

jjstr8
Collaborator
Collaborator

The code you posted does not show where the "Error adding ribbon tab" message is generated. The only thing that looks a little off is your arguments in your .RibbonTabs.Add call. Where you have "Part" it should be ClientID. It's also good practice to pass optional parameters by name, for clarity. In any case, what you had ran for me.

 

If awiTab Is Nothing Then
    ' Create new Ribbon Tab (Visible in all file types)
    awiTab = uiMgr.Ribbons.Item("Part").RibbonTabs.Add("AWI Tools", "AWI_Tools_Tab", ClientId, TargetTabInternalName:="Part", InsertBeforeTargetTab:=True)
    MsgBox("Ribbon tab created successfully.")
End If

 

 

0 Likes
Message 3 of 3

hollypapp65
Advocate
Advocate

My Ribbon setup code:

    Private Sub RibbonSetup()
      Dim oRibbon As Ribbon
      Dim oTab As RibbonTab
      Dim oPanel As RibbonPanel
      Dim oUIManager As UserInterfaceManager

      ' Set a reference to the user interface manager.
      oUIManager = m_inventorApplication.UserInterfaceManager

      ' Get the ribbon associated with documents
      oRibbon = oUIManager.Ribbons.Item("Part")
      'oRibbon = oUIManager.Ribbons.Item("Drawing")
      ' Get tab
      oTab = oRibbon.RibbonTabs.Item("id_TabModel")

      ' Get panel within the tab
      oPanel = oTab.RibbonPanels.Item("id_PanelA_ModelWorkFeatures")
      'oPanel = oTab.RibbonPanels.Add("COG Features", "id_PanelA_COGFeature", m_AddInCLSID, "id_PanelA_ModelWorkFeatures", False)

      ' Create a control within the panel
      Call oPanel.CommandControls.AddButton(M_COGBtDef, True)

      oRibbon = oUIManager.Ribbons.Item("Assembly")
      'oTab = oRibbon.RibbonTabs.Item("id_TabModel")
      oTab = oRibbon.RibbonTabs.Item("id_TabAssemble")

      oPanel = oTab.RibbonPanels.Item("id_PanelA_ModelWorkFeatures")
      'oPanel = oTab.RibbonPanels.Add("COG Features", "id_PanelA_COGFeature", m_AddInCLSID, "id_PanelA_ModelWorkFeatures", False)
      Call oPanel.CommandControls.AddButton(M_COGBtDef, True)

    End Sub
0 Likes