Overview RSS Feed


    Both the Windows and Mac versions of Rhino contain support for the Python scripting language. Python is a modern programming language developed for remarkable power with very clear syntax. Come join all the others looking at this new tool.
    What about RhinoScript?
    Rhino already has a very successful scripting language called RhinoScript. There are no plans to stop supporting RhinoScript and we plan to continue to add functions to RhinoScript based on user 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 very 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 at http://www.rhino3d.com/5/ironpython/index.html

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

    RhinoScript Version
    VB Code:
      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 Code:
      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.
    Python Code:
      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 quick links that you might find useful

    A good place to start is at the Rhino.Python community site on our Tutorials page...
    You also can find resources on Python on our resources page...