Message 1 of 3
help with code to create a new Ribbon Tab in Inventor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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