RhinoScriptSynthax


import rhinoscriptsyntax as rs


RhinoScriptSynthax is a Python library that simplifies the RhinoCommon library. Consider it as a toolbox that contains a set of functions to create and modify geometries in Rhino. It contains only:


Note that RhinoScriptSynthax is a wrapper around RhinoCommon and it is less powerful than RhinoCommon. It is a good library to start with if you are new to Python and Rhino. You can go fast and see results quickly. However, if you want to go further and have functionalities over the geometries, you will have to switch to RhinoCommon.

Often it is used with scriptcontext to access the document and the objects contained in it.

import scriptcontext


🔎🔎🔎 To check what is contained in the library, check the RhinoScriptSynthax documentation. 🔎🔎🔎


Let’s see the basics to manipulate geometries in Rhino with RhinoScriptSynthax..


Add object

Create a geometric object (in memory):

import rhinoscriptsyntax as rs

# ⚠️ ⚠️ ⚠️ with RhinoScriptSynthax, you cannot create a geometric object 
# in memory, you can only add it to the document and then coerce it to a 
# Rhino.Geometry object
guid_point = rs.AddPoint([0,0,0])
point = rs.coerce3dpoint(guid_point)
print(point)  # Rhino.Geometry.Point3d


Coercion is the process of converting a RhinoScriptSynthax object to a Rhino.Geometry object.


Get object

Get the geometric object from the RhinoDocument:

import rhinoscriptsyntax as rs

# retrieve the object from the document
guid_point = rs.GetObject("Select a point")

# coerce (cast) the object to a Rhino.Geometry object
point = rs.coerce3dpoint(guid_point)
print(type(point))  # Rhino.Geometry.Point3d



Replace object

Replace the geometric object from the RhinoDocument:

import rhinoscriptsyntax as rs
import scriptcontext

# add a point
guid_point = rs.AddPoint([0,0,0])
point = rs.coerce3dpoint(guid_point)

# modify the point's coordinates
point.X = 10
point.Y = 10
point.Z = 10

# replace the point in the document
scriptcontext.doc.Objects.Replace(
    guid_point,  # the guid of the object to replace
    point        # the new geometric object (in memory)
)



Duplicate object

Duplicating the geometric object from the RhinoDocument:

import rhinoscriptsyntax as rs

# add a point
guid_point = rs.AddPoint([0,0,0])

# duplicate the point
guid_point_duplicate = rs.DuplicateObject(guid_point)

print(guid_point != guid_point_duplicate)  # True



Delete object

Delete the geometric object from the RhinoDocument:

import rhinoscriptsyntax as rs

# add two points
guid_point_A = rs.AddPoint([0,0,0])
guid_point_B = rs.AddPoint([10,10,10])

# delete the second point
rs.DeleteObject(guid_point_B)


🛠 Exercise


🦏⬇️⬇️⬇️ Download the Rhino file here ⬇️⬇️⬇️🦏

Create: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 Get: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 Duplicate: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 Replace: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍