Hi @isocam. That is a complex task, partially because of how custom it is. Generally speaking, you do not have one VBA macro that does some sort of task, and also adds itself as a button into your ribbon. So, you would need a regular VBA Module stored within the application VBA project, and its first/primary method must be a Sub routine (not a Function), and it must not have any 'input' parameters. Then there must be a different VBA macro specifically for adding that other macro to the ribbon as a macro button. This second macro (for creating the button) needs to specify which Environment / Ribbon to work with (usually the active one), which RibbonTab within that Ribbon, which RibbonPanel within that RibbonTab, where to place it among any existing controls within that panel, and so on. The ControlDefinition must either already exist, or be created. Then the CommandControl (actual button) needs to be created that uses that ControlDefinition. Below are two VBA codes. The first one is just for showing "HELLO WORLD!", and the second one is for creating the button.
Show the message: [Module named "HelloWorld", and Sub routine named "HelloWorld".]
Sub HelloWorld()
Call MsgBox("HELLO WORLD!", vbOKOnly, "HELLO WORLD")
End Sub
Create the button for it: [Module named "AddMacroButton", Sub routine named "AddMacroButton".]
Sub AddMacroButton()
Dim UIMgr As Inventor.UserInterfaceManager
Set UIMgr = ThisApplication.UserInterfaceManager
Dim oRibbon As Inventor.Ribbon
Set oRibbon = UIMgr.ActiveEnvironment.Ribbon
Dim sTabName As String
sTabName = UIMgr.ActiveEnvironment.DefaultRibbonTab
Dim oRTab As Inventor.RibbonTab
Set oRTab = oRibbon.RibbonTabs.Item(sTabName)
oRTab.Visible = True
oRTab.Active = True
Dim oPanels As Inventor.RibbonPanels
Set oPanels = oRTab.RibbonPanels
Dim oFirstPanel As Inventor.RibbonPanel
Set oFirstPanel = oPanels.Item(1)
oFirstPanel.Visible = True
Dim oCCs As Inventor.CommandControls
Set oCCs = oFirstPanel.CommandControls
Dim oCDs As Inventor.ControlDefinitions
Set oCDs = ThisApplication.CommandManager.ControlDefinitions
Dim oMacroCD As Inventor.MacroControlDefinition
Dim oMCD As ControlDefinition
For Each oMCD In oCDs
If oMCD.InternalName = "HelloWorld.HelloWorld" Then
Set oMacroCD = oMCD
oMacroCD.Enabled = True
End If
Next
If oMacroCD Is Nothing Then
Set oMacroCD = oCDs.AddMacroControlDefinition("HelloWorld.HelloWorld")
oMacroCD.Enabled = True
'Call MsgBox("Macro ControlDefinition Not Found!", vbCritical, "Not Found")
'Exit Sub
End If
Dim oMacroButtonControl As Inventor.CommandControl
Set oMacroButtonControl = oCCs.AddMacro(oMacroCD, False, True)
oMacroButtonControl.Visible = True
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)