Site Tools


Python scripting for Rhino

http://python.rhino3d.comhttp://python.rhino3d.com
community site for using python in Rhino.

Windows and Mac

Both the Windows and Mac versions of Rhino contain support for the Python scripting language.

Since Rhino python scripting is available on both Windows and Mac, the exact same python scripts will run on both “breeds” of Rhino!

What about RhinoScript?

Rhino already has a very successful scripting language called RhinoScript. There are no plans to stop supporting RhinoScript and we will continue to add functions to RhinoScript based on requests. Python can be considered an alternative scripting language that you may want to use for writing scripts.

RhinoScript style functions

One of the key features of RhinoScript that make it easy to write powerful scripts is a large library of Rhino specific functions that can be called from scripts. Our python implementation includes a set of similar functions that can be imported and used in any python script for Rhino. This set of functions is known as the rhinoscript package. Documentation on this package can be found here.

Let's compare scripts for letting a user pick two points and adding a line to Rhino.

RhinoScript Version

Dim arrStart, arrEnd
arrStart = Rhino.GetPoint("Start of line")
If IsArray(arrStart) Then
  arrEnd = Rhino.GetPoint("End of line")
  If IsArray(arrEnd) Then
    Rhino.AddLine arrStart, arrEnd
  End If
End If

Python version

import rhinoscriptsyntax as rs
 
start = rs.GetPoint("Start of line")
if start:
  end = rs.GetPoint("End of line")
  if end: rs.AddLine(start,end)

Different… but similar enough that you should be able to figure out what is happening in python if you've written RhinoScript.

Using RhinoCommon

Along with the RhinoScript style functions you will be able to use all of the classes in the .NET Framework, including the classes available in RhinoCommon. As a matter of fact, if you look at the source for the RhinoScript style functions, they are just python scripts that use RhinoCommon. This allows you to do some pretty amazing things inside of a python script. Many of the features that once could only be done in a .NET plug-in can now be done in a python script.

For example, you can implement some custom drawing while a user is picking a point with the following script. This script draws a Red and Blue line connected to the point under the mouse cursor while the user is picking a point.

import Rhino
import System.Drawing
 
def GetPointDynamicDrawFunc( sender, args ):
  pt1 = Rhino.Geometry.Point3d(0,0,0)
  pt2 = Rhino.Geometry.Point3d(10,10,0)
  args.Display.DrawLine(pt1, args.CurrentPoint, System.Drawing.Color.Red, 2)
  args.Display.DrawLine(pt2, args.CurrentPoint, System.Drawing.Color.Blue, 2)
 
# Create an instance of a GetPoint class and add a delegate for the DynamicDraw event
gp = Rhino.Input.Custom.GetPoint()
gp.DynamicDraw += GetPointDynamicDrawFunc
gp.Get()

Resources

Here are a few links that you might find useful

Samples that use rhinoscriptsyntax

2007/11/28  
2010/01/12  
2010/01/12  
2010/01/12  
2010/01/12  
2012/04/19 John Morse
2010/01/12  
2012/04/19 John Morse
2012/04/19 John Morse
2012/04/19 John Morse
2012/04/19 John Morse
2012/04/19 John Morse
2012/04/19 John Morse
2012/04/19 John Morse
2012/04/19 John Morse
2012/04/19 John Morse
2012/04/19 John Morse
2012/04/19 John Morse
2013/05/14 John Morse
2012/04/19 John Morse

Samples that use RhinoCommon

2012/05/08 Giulio
2010/01/12  
2012/08/03 Steve Baer
2012/09/28 Dale Fugier
2011/03/17 Steve Baer
2011/05/21 Steve Baer
2011/11/06 Steve Baer
2010/07/30 Steve Baer
2010/07/30 Steve Baer
2010/12/20 Steve Baer
2010/07/30 Steve Baer
2010/07/30 Steve Baer
2011/01/12 Steve Baer
2011/01/15 Steve Baer
2011/01/03 Steve Baer
2011/07/14 Steve Baer
2010/07/30 Steve Baer
2010/07/30 Steve Baer
2010/07/30 Steve Baer
2010/07/30 Steve Baer
2010/07/30 Steve Baer
2010/07/30 Steve Baer
2010/07/30 Steve Baer
2010/07/30 Steve Baer
2010/07/30 Steve Baer
2010/08/02 Steve Baer
2010/08/02 Steve Baer
2010/09/01 Steve Baer
2010/09/01 Steve Baer
2010/09/01 Steve Baer
2011/05/28 Steve Baer
2011/05/28 Steve Baer
2011/11/30 Steve Baer
2011/03/10 Steve Baer
2011/08/12 Dale Fugier
2011/06/04 Steve Baer
2012/01/27 Steve Baer
2011/11/07 Steve Baer
2011/06/04 Steve Baer
2012/08/14 Steve Baer
2010/12/16 Steve Baer
2010/12/29 Steve Baer
2011/07/26 Steve Baer
2010/07/30 Steve Baer
2011/03/20 Steve Baer
2011/11/07 Steve Baer
2012/01/31 Steve Baer
2011/03/10 Steve Baer
2010/09/01 Steve Baer
2011/01/15 Steve Baer
2011/03/10 Steve Baer
2011/03/22 Steve Baer
2012/05/16 Steve Baer
2011/06/01 Steve Baer
2011/01/18 Steve Baer
2011/01/15 Steve Baer
2010/07/30 Steve Baer
2010/12/16 Steve Baer
2011/03/19 Steve Baer
2011/05/28 Steve Baer
2011/11/06 Steve Baer
2011/03/10 Steve Baer
2011/02/05 Steve Baer
2011/05/19 Steve Baer
2011/11/05 Steve Baer
2011/06/16 Steve Baer
developer/python.txt · Last modified: 2012/11/09 by steve