Message 1 of 2

Not applicable
03-01-2020
06:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi to Community;
Please help me to assign a macro for a button definition; and I need to add it to a pop up.
(I need to add a handler for button definition in VBA)
Thanks in advance.
This code works but (the) buttons do not.. 🙂
Sub SetRibbon_UsingClass()
Dim aClass As clsCustomButton
Set aClass = New clsCustomButton
aClass.SetButtonPopup
End Sub
Option Explicit
'Class Module: clsCustomButton
Private WithEvents oButtonDefinition1 As ButtonDefinition
Private WithEvents oButtonDefinition2 As ButtonDefinition
Private Sub oButtonDefinition1_OnExecute(ByVal Context As NameValueMap)
MsgBox ("oButDefinition1 : command is running")
End Sub
Private Sub oButtonDefinition2_OnExecute(ByVal Context As NameValueMap)
MsgBox ("oButDefinition2 : command is running")
End Sub
Sub SetButtonPopup()
Dim oRibbon As Inventor.ribbon
Dim oTab As RibbonTab
Dim oPanel As RibbonPanel
Dim oButDefs As ObjectCollection
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim ClientId As String
ClientId = "SampleClientId"
Set oRibbon = ThisApplication.UserInterfaceManager.Ribbons.item("Assembly")
Set oTab = oRibbon.RibbonTabs.item("id_TabTools")
oTab.Active = True
Set oPanel = oTab.RibbonPanels.Add("Assembly Tool B", "ToolsTabAssemblyPanel-B", ClientId)
'ADD BUTTON POPUP
Set oButtonDefinition1 = ThisApplication.CommandManager.ControlDefinitions.AddButtonDefinition( _
"Button 1", "oButDefinition1", _
kEditMaskCmdType, ClientId, _
"Description 1", "ToolTipText 1", , , _
kDisplayTextInLearningMode)
Set oButtonDefinition2 = ThisApplication.CommandManager.ControlDefinitions.AddButtonDefinition( _
"Button 2", "oButDefinition2", _
kEditMaskCmdType, ClientId, _
"Description 2", "ToolTipText 2", , , _
kDisplayTextInLearningMode)
Set oButDefs = ThisApplication.TransientObjects.CreateObjectCollection
oButDefs.Add oButtonDefinition1
oButDefs.Add oButtonDefinition2
Call oPanel.CommandControls.AddButtonPopup(oButDefs)
End If
End Sub
Solved! Go to Solution.