Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I would like to add buttons to a custom ribbon panel, and I'd like those buttons to point to macros. I can't find any examples to do this.
Here is what I have so far, based on the sample code from the API help. This creates a new ribbon panel and adds buttons for standard commands. I'd like to add a 4th button that points to a macro.
Thanks in advance,
Curtis
Sub AddPanelToToolsTab()
' Get the ribbon associated with the part document
Dim oPartRibbon As Inventor.Ribbon
Set oPartRibbon = ThisApplication.UserInterfaceManager.Ribbons.Item("Part")
'Get the "Tools" tab
Dim oTab As RibbonTab
Set oTab = oPartRibbon.RibbonTabs.Item("id_TabTools")
oTabName = "Custom"
Dim oPanel As RibbonPanel
For Each oPanel In oTab.RibbonPanels
If oPanel.DisplayName = oTabName Then
oPanel.Delete 'remove it
End If
Next
' Create a panel
Set oPanel = oTab.RibbonPanels.Add(oTabName, "ToolsTabCustomPanel", "SampleClientId")
' Get the update commands
Dim oDef1 As ButtonDefinition
Set oDef1 = ThisApplication.CommandManager.ControlDefinitions.Item("AppLocalUpdateCmd")
Dim oDef2 As ButtonDefinition
Set oDef2 = ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd")
Dim oDefs As ObjectCollection
Set oDefs = ThisApplication.TransientObjects.CreateObjectCollection
oDefs.Add oDef1
oDefs.Add oDef2
' Create a split button control
Call oPanel.CommandControls.AddSplitButton(oDef1, oDefs, False)
' Get the rebuild command
Dim oDef3 As ButtonDefinition
Set oDef3 = ThisApplication.CommandManager.ControlDefinitions.Item("AppRebuildAllWrapperCmd")
' Create a button control
Call oPanel.CommandControls.AddButton(oDef3, False)
' 'create button for custom macro
' Dim oDef4 As ButtonDefinition
' Call oPanel.CommandControls.AddButton(oDef4, False)
End Sub
Solved! Go to Solution.