Active Contributor
Posts: 28
Registered: ‎01-31-2014
Message 1 of 3 (133 Views)
Accepted Solution

Add command To button

133 Views, 2 Replies
04-03-2014 04:33 AM

This is my button


  Dim pan1button1 As New RibbonButton()
            pan1button1.Text = "STORE"
            pan1button1.ShowText = True
            pan1button1.ShowImage = True
            pan1button1.Image = Images.getBitmap(My.Resources.Store)
            pan1button1.LargeImage = Images.getBitmap(My.Resources.Store_L)
            pan1button1.Orientation = System.Windows.Controls.Orientation.Vertical
            pan1button1.Size = RibbonItemSize.Large
            pan1button1.CommandHandler = New RibbonCommandHandler

 I have had a look online but i can seem to find how i assign the macro to the button


The macro i want to use it


"^C^C_StoreTree "


Thanks in advance

*Expert Elite*
Posts: 987
Registered: ‎04-27-2009
Message 2 of 3 (116 Views)

Re: Add command To button

04-03-2014 07:13 AM in reply to: makepeace1


Basically, you specify the CommandHandler and CommandParameter properties of a ribbon item (button, in your case):


pan1button1.CommandHandler= New MyRibbonCommandHandler()

pan1button1.CommandParameter="^C^C_StoreTree "


Then you implement ICommand interface


Public class MyRibbonCommandHandler

    Implement System.Windows.Input.ICommand


   Public Function CanExecute(...)


   End Function


   Public Event ....


   Public Sub Execute(parameter As Object) Implement....

     Dim doc As Document=Application.DocumentManager.MdiActiveDocument

     Dim riboonItem As RiboonCommandItem=TryCast(parameter, RibbonCommandItem)

     If ribbonItem IsNot Nothing Then

       doc.SendStringToExecute(ribbonItem.CommandParameter, True, False, True)

     End If

   End Sub


End class


Note the code here is just right off my head and entered through Visual Studio, not compiled, thus could have sytex error. Just meant to give you an idea how to do it.

Active Contributor
Posts: 28
Registered: ‎01-31-2014
Message 3 of 3 (112 Views)

Re: Add command To button

04-03-2014 07:17 AM in reply to: norman.yuan



I have just managed to get it sorted just before i got your message


I am using The button's ID to run the macro
(i have since added the ID to it )


and then is what i had further down


        Public Class RibbonCommandHandler
            Implements System.Windows.Input.ICommand

            Public Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
                Return True
            End Function

            Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged

            Public Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute
                Dim doc As Document = Application.DocumentManager.MdiActiveDocument

                If TypeOf parameter Is RibbonButton Then
                    Dim button As RibbonButton = TryCast(parameter, RibbonButton)
                    doc.SendStringToExecute(button.Id & " ", True, False, False)
                End If
            End Sub

        End Class

 I have just changed this line so that it looks form the button ID and then executes it


doc.SendStringToExecute(button.Id & " ", True, False, False)
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.