GhPython
For designers who want to use the same flexible language everywhere, GhPython is the Python interpreter component for Grasshopper that allows to execute dynamic scripts of any type. Unlike other scripting components, GhPython allows to use the rhinoscriptsyntax to start scripting without needing to be a programmer. Once on-board and with some practice, you can also get the most of external Python and .Net modules and libraries.
This component is open-source, and works in Rhino 5. Join this group to receive updates of new versions, and visit the Grasshopper forum for support.
To install:
- In Grasshopper, choose File > Special Folders > Components folder. Save the gha file there.
- Right-click the file > Properties > make sure there is no "blocked" text
- Restart Rhino and Grasshopper

Comments
I was wondering if there's some way to access the complete list of parameters passed to the Python component. For example when I pass a list of vectors to the python code as 'x', and then try and manipulate 'x', whatever I do is applied to each member of the list, not to the entire list. I understand that this is desirable in many cases and consistent with how the other GH components work, but sometimes I want to manipulate the entire list. Is there a way to do this?
Oh wait, nevermind *sheepish look* I think I found something under -> 'input manager' -> 'list access'
OK, maybe I do still need some help figuring this out. It allows me to access the list, but it doesn't recognize 'append' as an attribute. For example, this bit of code gives an error ( Solution exception: 'List[object]' object has no attribute 'append' ):
import math
import rhinoscriptsyntax as rs
x.append(x[0])
a = x
Hi Sun,
the new component for Grasshopper 0.8.50 should fix this. It returns the IronPython List type instead of the List type.
Thanks,
- Giulio
Now nothing works. :-( A simple script with only this:
a = x
Creates no output to 'a'. This:
a = x[0]
generates a 'index out of range' error.
When I mouse over the 'x' on the input it shows that it has 48 values in it, but when I check it in the python script it is a zero length list.
Hi again Sun,
yes, I realized there was this error in release 0.4.5.1. Just a few minutes after that, release 0.4.5.2 should fixed it.
Thanks,
- Giulio
Is there some way to check which version I have? I downloaded the file again from the 0.4.5.2 link and replaced the one I was using, but it behaves exactly the same, so I think I already had 0.4.5.2 and it doesn't work.
Is nobody else having trouble? I'm running Rhino Version 5.0 (5.1.2011.804, 2011-08-04), and Grasshopper 0.8.0050, on Vista Ultimate 64. In the file linked below (hopefully, I've never used google docs before) I have two identical script components. The point list seems to come in ok, but the vector list doesn't. Any suggestions?
https://docs.google.com/leaf?id=0B_lWCiLxhdhLZmVlYzdkODItMjhiZS00MTEzLWF...
Hi again Sun,
now that you posted the file, I was having this issue as well :)
Please feel free to post support questions such as this one to the Grasshopper forum: http://www.grasshopper3d.com/forum/categories/vb-c-and-python-coding/lis...
Thanks,
- Giulio
Great. The new version seems to work better. Thanks! Did I post my inquiry in the wrong place?
Comments are good for first-time users to find information, but for support it's easier to use the forum because it makes file upload simpler.
Thanks,
- Giulio
hi,all,
i downloaded ghpython, but i cant install it. my gh version is build 0.8.0010. anyone can help me with that ...thanks
Dear gangsongcns,
I've copied this support request to the Grasshopper forum:
http://www.grasshopper3d.com/forum/topics/hi-all-i-downloaded-support-re
... and answered there.
I hope this helps,
- Giulio
Hi Steve,
I'm trying to get the most recent python component for GH to work with R5. Here is the code I'm running (from the sample).
-----------------
import rhinoscriptsyntax as rs
for i in xrange (x):
for j in xrange (y): rs.AddPoint(i,j,3)
plane = rs.PlaneFromNormal ((x,y,0), (0,0,1))
rs.AddArc(plane,12,80)
rs.AddArc3Pt((0,0,0),(x,y,0),(x*2,y,0))
rs.AddCircle(plane, x)
rs.AddCone((0,0,0),y,x)
pts = (0,0,0), (10,0,0), (10,x,0), (y,x,0)
rs.AddCurve(pts)
rs.AddCylinder((x,y,0),x,y)
geometry = ghdoc.Objects.Geometries
-----------------
I have two sliders connected to X and Y, set to 2 and 4 respectively.
When I right-click on the component and select "In ghdoc variable", then the "out" output says "no data was collected", and the "a" output says "". If I go back and select "Rhino document" then the code generates Rhino geometry in the Rhino modeling environment, as expected. However, I get an error in the "out" output that says:
{0;0}
0. Runtime error (UnboundNameException): name 'ghdoc' is not defined
1. Traceback: line 14, in script
Can you help me out with this? What do I need to do to get the sliders engaged? Thanks, Matt
Hi Matt,
your code works here.
You just need to be sure that the variable you assign to is the output variable (by default it is "a" in a new component) and you have ghdoc as target. The last two lines, then, become:
----
cyl = rs.AddCylinder((x,y,0),x,y)
a = ghdoc[cyl] # this gives the cylinder
----
or
----
rs.AddCylinder((x,y,0),x,y)
a = ghdoc # this returns everything in the "a" output
---
I hope this helps,
- Giulio
Ok, got it. That works. Thanks so much, Giulio. What would I need to do to add another input for a 'z' slider?
Matt
Hi Matt, you can right click the middle of the component and choose "Input Manager...".
- Giulio
Great, that's exactly what I needed.
Thanks again Giulio!
Matt
Hi
Now that i installed the last version of Rhino5
the Python component for Grasshopper works fine
Thanks
Thank you, nice to hear this.
- Giulio
Hi.
I might just be looking the wrong places, but I have a hard time finding info on how to use the GHPython component, especially how to export geometry from the component and display it, work on etc. The input function seems pretty simple, except I am still not sure what the right way to import geometry is?
It seems in the general picture from www.grasshopper3d.com group that at the end of the python script, a speciel "ghdoc" or something is used.
Can I get a short explanation, intro or something somewhere? I have been working a lot in both platforms so, I am really excited about bringing them together.
Thanks Rasmus
Hi Rasmus,
the next version of the component will come with a list of Q&A when you choose Help... on the component context menu.
Now you can find quite some of them here: http://www.grasshopper3d.com/forum/topics/some-ghpython-confusion?commen... .
I hope this helps,
- Giulio
Python component for Grasshopper v 0.4.2.0 does not working !!!
Isent email (screen shot) to david@mcneel.com
Hi Msahli,
could you please add this question as a discussion on the Grasshooper forum?
http://www.grasshopper3d.com/forum/categories/vb-c-and-python-coding/lis...
Thanks,
- Giulio