Add button in toolbar with rhinoscript

Hello
How can I make a button for the toolbar using Rhino Script?
The following command does not work!!!
Rhino.AddToolbarButton strname , strtoolbar
thank you

Option Explicit

Sub CreateToolbarButton()
    Dim strToolbar, strButton, strMacro
    
    ' Name of the toolbar where the button will be added
    strToolbar = "MyToolbar"
    
    ' Name of the button
    strButton = "MyButton"
    
    ' Macro that will be executed when the button is clicked
    strMacro = "_MyCommand"
    
    ' Add the button to the toolbar
    Rhino.AddToolbarButton (strToolbar, strButton)
End Sub

Thank you for your answer, but I encountered two problems in this code:
q1
notwork

Rhino.AddToolbarButton (strToolbar, strButton) is passed with 2 arguments, strToolbar so the receiving toolbar, and strButton so the button you’re adding.
The fact that AddToolbarButton is deprecated is new to me.
@dale surely knows what’s up

1 Like

This might have worked in like Rhino 4, but as far as I know it hasn’t since - the toolbar system has been revamped so many times since then. In Rhino 5 already I get the “obsolete” message.

image

You also need to call the sub to run it.

Option Explicit

Call CreateToolbarButton()
Sub CreateToolbarButton()
	Dim strToolbar, strButton, result
    
	' Name of the toolbar where the button will be added
	strToolbar = "Testing"
    
	' Name of the button
	strButton = "TestButton"
    
	' Add the button to the toolbar
	result = Rhino.AddToolbarButton(strToolbar, strButton)
End Sub

In V7 the method returns Null:

Option Explicit

Call CreateToolbarButton()
Sub CreateToolbarButton()
	Dim strToolbar, strButton, result
    
	' Name of the toolbar where the button will be added
	strToolbar = "Test"
    
	' Name of the button
	strButton = "TestButton"
    
	' Add the button to the toolbar
	result = Rhino.AddToolbarButton(strToolbar, strButton)
	If IsNull(result) Then
		Call Rhino.MessageBox("Method returned Null!")
	End If
End Sub

image

1 Like

I haven’t used rhinoscript in a long while, I’m not sure why It’s still showing in the SDK docs for Rh7 if deprecated for such a long time.
Thank you for letting me know :smiling_face_with_three_hearts: