ghPython – Outside the Canvas
As a follow up to my post about the new features in ghPython, I wanted to point out another feature now available; running Grasshopper components outside of the Grasshopper canvas.
You will need to have installed ghPython and have used the component in grasshopper at least once. We will fix the “at least once” issue in a future release of ghPython.
- Start Rhino
- Run EditPythonScript and enter the following script
import rhinoscriptsyntax as rs import ghpythonlib.components as ghcomp import scriptcontext points = rs.GetPoints(True, True) if points: curves = ghcomp.Voronoi(points) for curve in curves: scriptcontext.doc.Objects.AddCurve(curve) for point in points: scriptcontext.doc.Objects.AddPoint(point) scriptcontext.doc.Views.Redraw()
- Run the python script
ghpythonlib (both components and parallel) modules are available in the standard python editor in Rhino. Behind the scenes things are running through Grasshopper code, but you don’t have to use a canvas to do your work.
This also lets you work in a slightly different way where you can get points in Rhino using rhinoscriptsyntax “get input” type functions and pass those points (or curves or breps) into the Grasshopper component code.