Template
In early stages of design computing experimentation, not all input and output parameters are known in advance. The recommended setup for this scenario is to prepare the component as seen below.
- Rename the
out
parameter tomessages
and connect a panel component, where you can view standard outputs and errors. - Create a
geometry
output parameter to publish any geometric objects to be displayed in the viewport.

When the specific format and type of output information becomes more clear, it is only a matter of creating new parameters and updating the code as needed.
Template Python Code
You may set the following code snippet as the default python script template by pasting the code below into the python script editor and selecting the Tools / Set Template Code...
menu item.
import math, random
from Rhino import RhinoApp, RhinoDoc
from Rhino.Geometry import ( Point3d, Vector3d, Plane, Transform,
Interval, Point2d, Point3f, Vector3f, Point2f, Line, Circle, Curve,
Surface, NurbsCurve, NurbsSurface, Brep, Mesh, Arc, ArcCurve,
BezierCurve, Box, Cone, ControlPoint, Cylinder, Ellipse, Extrusion,
LineCurve, LoftType, Point4d, PointCloud, PolyCurve, Polyline,
PolylineCurve, Quaternion, Sphere )
from Rhino.Geometry.Intersect import Intersection
from System.Drawing import Color
geometry = []
def Add( element ):
geometry.append( element )
''' Script Below
'''
Add( Point3d( 0, 1, 2 ) )
print( 'done' )

- The
math
module is used for accessing built-in mathematics functions such assin
,cos
,sqrt
,exp
etc. See relevant documentation. Therandom
provides random number generators. - The
RhinoDoc
class enables direct manipulation of Rhino's currently opened document. It can be used for loading and saving geometries outside of Grasshopper. See relevant documentation. TheRhinoApp
class accesses the application itself. - The
Geometry
namespace contains definitions for creating and manipulating points, vectors, curves, surfaces, meshes, breps etc. See relevant documentation - The
Intersect
namespace contains definitions for computing intersections between different kinds of geometries. See relevant documentation. - The
Color
class is used for creating color objects as defined by the .NET system and used by Rhino. See relevant documentation
Annotated Template
It is often useful to visualize text labels at specific points in the viewport. As it is not possible to emit certain types of visuals from python components, we need to adapt the template to output pairs of points and labels and use the Text Tag 3D
component. The cluster is used for decoupling the data packed in lists.
import math, random
from Rhino import RhinoApp, RhinoDoc
from Rhino.Geometry import ( Point3d, Vector3d, Plane, Transform,
Interval, Point2d, Point3f, Vector3f, Point2f, Line, Circle, Curve,
Surface, NurbsCurve, NurbsSurface, Brep, Mesh, Arc, ArcCurve,
BezierCurve, Box, Cone, ControlPoint, Cylinder, Ellipse, Extrusion,
LineCurve, LoftType, Point4d, PointCloud, PolyCurve, Polyline,
PolylineCurve, Quaternion, Sphere )
from Rhino.Geometry.Intersect import Intersection
from System.Drawing import Color
geometry = []
def Add( element ):
geometry.append( element )
annotations = []
def Anno( point, label ):
annotations.append( [point, label] )
''' Script Below
'''
source = Point3d.Origin
target = Point3d.Origin + Vector3d.XAxis
Anno( source, 's' )
Anno( target, 't' )
Add( Line( source, target ) )

Vectors Template
The template provided below simplifies the process of visualizing vectors. The Vec( )
method can be used to specify the origin and direction as well as the color of a 3D vector, which is then rendered using the Vector Display Ex
component. The cluster is used for decoupling the data packed in lists.
import math, random
from Rhino import RhinoApp, RhinoDoc
from Rhino.Geometry import ( Point3d, Vector3d, Plane, Transform,
Interval, Point2d, Point3f, Vector3f, Point2f, Line, Circle, Curve,
Surface, NurbsCurve, NurbsSurface, Brep, Mesh, Arc, ArcCurve,
BezierCurve, Box, Cone, ControlPoint, Cylinder, Ellipse, Extrusion,
LineCurve, LoftType, Point4d, PointCloud, PolyCurve, Polyline,
PolylineCurve, Quaternion, Sphere )
from Rhino.Geometry.Intersect import Intersection
from System.Drawing import Color
geometry = []
def Add( element ):
geometry.append( element )
vectors = []
def Vec( point, direction, color = Color.Black ):
vectors.append( [point, direction, color] )
''' Script Below
'''
source = Point3d.Origin
target = Point3d.Origin + Vector3d.XAxis
Vec( source, target - source, Color.Blue )
Add( Line( source, target ) )
