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__':
MyScriptName()
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:
MyScriptName()
HTH,
–Mitch
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=HiThere(your_name)
else:
ret_msg="Sorry, I didn't get your name"
rs.MessageBox(ret_msg)
RunMyScript()
)