Python script to Rhino button


From another thread jeff_hammond was kind to share a python script [! _Line _BothSides] . I’m trying to create a button for it. Viewed the script in the Rhino Python editor, but don’t know what to paste in the button window. Have zilch experience with scripts and little in creating my own button.
A bit off topic , but I would also like to create another button for the test commands in Rhino 5 " _TestRemoveNakedMicroLoops and _TestRemoveAllNakedMicroLoops " . Preferably in one one button, left and right click for the 2 commands …Thanks for any help

Rhino file size Again:

Create a new blank button, open the editor then put in the following:

! _-RunPythonScript (

<paste entire script in here>


HTH, --Mitch


The script seems very long and I’m not sure what to copy and paste. Thanks for the reply


Length doesn’t matter, just paste it all in there.

If the script was posted as a .py file and it runs from the script editor, you don’t need to add anything. Open the file in a text editor, Ctrl+A to select all, Ctrl+C to copy the whole text, switch to the button editor. Type in the first line or copy it from here :

! _-RunPythonScript (

Then return to get a new line and Ctrl+V to paste the text in.

Then another return and type a close parentheses alone on one line, that will be the end.

Then OK to close the button editor.

One thing to watch out for - some people have the habit of ending their Python scripts with

if __name__ == '__main__':

This runs in a script editor, but unfortunately does not work inside a button. so you will have to remove the entire if __name__ == '__main__': line and outdent the MyScriptName() all the way to the left (usually 4 spaces) so the last line of the script looks like this:




Edit: here is a typical script to paste into a button to test

! _-RunPythonScript (

"""Hello test script"""
import rhinoscriptsyntax as rs

def HiThere(name):
    if name:
        return "Hello {}, this script runs fine.".format(name)

def RunMyScript():
    your_name=rs.StringBox("What is your name?")
    if your_name:
        ret_msg="Sorry, I didn't get your name"



Thanks for the help