Python component for Grasshopper
byon 05-02-2011 at 11:56 PM (11372 Views)
Giulio Piacentino and I have been working on an update to the grasshopper/python component and finally have something to show off!!!
http://www.food4rhino.com/project/ghpython - NOTE: Will only work in Rhino 5
This component is a scripting component similar to the VB.NET and C# components that ship with Grasshopper. You get a component where you can define as many input and output variables as you want and then reference these variables in the python script.
If you double click on the component, you get a light version of the python script editor which you are used to in the EditPythonScript command (keywords are colorized and functions autocomplete when possible)
But there is a cool twist... this component supports the rhinoscriptsyntax functions. The rhinoscriptsyntax functions can be set to generate geometry inside of Grasshopper that does not live in the Rhino document. We are using a concept called "duck typing" to swap the document that the rhinoscriptsyntax functions use from the rhino document to a grasshopper document. This means that the following script
will add 10 points to the Rhino document when run from Rhino's "RunPythonScript" or "EditPythonScript" functions. The same script will add 10 points to a grasshopper document that can be passed on to other grasshopper components when run inside the syntax of grasshopper.Python Code:
import rhinoscriptsyntax as rsfor x in range(10):rs.AddPoint((x,0,0)
We are writing this as an open source project which is hosted at
Developers are welcome to download, compile, and tinker with the component source code. If you find bugs or want to add features, let us know and we'll figure out how to get you more involved in the development process.
You can also log bugs and wishlist items at
Use your python scripting skills in Rhino 5 for Windows, Rhino 5 for Mac, and in Grasshopper for Rhino 5