Skip to content
April 11, 2011 / stevebaer

Running scripts from Toolbar buttons

This is only for Windows Rhino right now since you can’t customize toolbar buttons on Mac yet, but once that feature becomes available I’m pretty sure the technique will be the same.

In Rhino, create a new toolbar button and edit it. Consult the Rhino help for for adding and editing toolbar buttons. Now you have three options (that I can think of at the moment) for adding a python script to a toolbar button. All of these involve executing the RunPythonScript command
editbutton

  1. Directly embed the script
    Make sure the first line reads -_RunPythonScript (. Note that there needs to be a space between RunPythonScript and the parentheses.
    Make sure the last line is just a closing parentheses. The lines in between are interpreted as your python script.

    -_RunPythonScript (
    import rhinoscriptsyntax as rs
    point0 = rs.GetPoint("start")
    point1 = rs.GetPoint("end")
    rs.AddLine(point0,point1)
    )
    
  2. Absolute path to the script
    -_RunPythonScript (C:\Users\a-steve\Desktop\CurveLength.py)
  3. Path to script on search path
    If the script is on python’s search path, you can use the following form to let python find the script (use period separate subdirectories.)
    -_RunPythonScript (Samples.CurveLength.py)

2 Comments

Leave a Comment
  1. issworld / Oct 23 2013 1:47 pm

    Very nice.
    Thank you.

  2. jedsonguedes / Aug 29 2015 2:14 am

    Thanks, man!
    It really helped me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: