View RSS Feed

Steve Baer

Python component for Grasshopper

Rate this Entry
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.
Click image for larger version

Name:	ghpython.jpg
Views:	522
Size:	88.9 KB
ID:	199
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)
Click image for larger version

Name:	ghpython_editor.png
Views:	429
Size:	67.7 KB
ID:	198

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
Python Code:
    import rhinoscriptsyntax as rs
    for x in range(10):
        rs.AddPoint((x,0,0)
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.

We are writing this as an open source project which is hosted at
https://github.com/mcneel/ghpython
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
https://github.com/mcneel/ghpython/issues

Use your python scripting skills in Rhino 5 for Windows, Rhino 5 for Mac, and in Grasshopper for Rhino 5
Thanks,
-Steve

Comments

  1. naimmohd -
    naimmohd's Avatar
    Congratulation Steve, it is a brilliant work
    thanks
  2. BenjaminGolder -
    BenjaminGolder's Avatar
    So. Freakin. Awesome.
    Thank you Steve and Giulio!!!
  3. p.drewello -
    p.drewello's Avatar
    Hey Steve,
    I've been meaning to ask. How does the ghpython component work in the context of the tree structures in gh. I.e. I know in C# you have to ensure you use the gh data trees to ensure you can plug your output into other components.
    Thanks.
    P