.NET

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

Add command To button

143 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

 

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.

*Expert Elite*
norman.yuan
Posts: 1,049
Registered: ‎04-27-2009
Message 2 of 3 (126 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
makepeace1
Posts: 28
Registered: ‎01-31-2014
Message 3 of 3 (122 Views)

Re: Add command To button

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

Thanks

 

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)
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!