VBA - AddButtonPopup - Need Help, can not assign macro to buttons

VBA - AddButtonPopup - Need Help, can not assign macro to buttons

Anonymous
Not applicable
506 Views
1 Reply
Message 1 of 2

VBA - AddButtonPopup - Need Help, can not assign macro to buttons

Anonymous
Not applicable

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.

 

000.png

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

 

0 Likes
Accepted solutions (1)
507 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

I used Visual Studio 2017 (I learned that VS 2019 is not supported by Inventor) and solve the problem.

I found a code from web ; "MenuDemo" and another code for calling existing VBA macros; and manipulate them for my purpose. Thanks.

001.png

 

...
        Private Sub Button4_Clicked(ByVal context As NameValueMap)
            RunMacro_VBA_RunSheetMetals()
        End Sub

        Public Sub RunMacro_VBA_RunSheetMetals()
            Dim oP As Inventor.InventorVBAProject
            For Each oP In m_inventorApplication.VBAProjects
                If oP.Name = "ApplicationProject" Then
                    Dim oC As Inventor.InventorVBAComponent
                    For Each oC In oP.InventorVBAComponents
                        If oC.Name = "Module_0" Then
                            Dim oM As Inventor.InventorVBAMember
                            For Each oM In oC.InventorVBAMembers
                                If oM.Name = "RunSheetMetals" Then
                                    oM.Execute()
                                End If
                            Next oM
                        End If
                    Next oC
                End If
            Next
        End Sub