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
Plug-in rating:
5
Average: 5 (11 votes)
Downloads:
Title Release Notes
0.4.6.0 - For Grasshopper 0.8.50
2011-Aug-06
This release is published to support Grasshopper 0.8.50. Grasshopper 0.8.13 and earlier are not supported. Several bugfixes, including input marshallings.  
3415 downloads
Version: 0.4.6.0
0.4.4 - Marshal & presentation
2011-Jul-20
Automatic marhalling for input and output variables with rhinoscriptsyntax component-level option. Python components now have presentation settings to improve visualization when development is finished.  
973 downloads
Version: 0.4.4.0

    
     
    
        
       
License: https://github.com/mcneel/ghpython

Comments

sun's picture

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?

sun's picture

Oh wait, nevermind *sheepish look* I think I found something under -> 'input manager' -> 'list access'

sun's picture

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

giulio's picture

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

sun's picture

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.

giulio's picture

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

sun's picture

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.

sun's picture

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...

giulio's picture

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

sun's picture

Great. The new version seems to work better. Thanks! Did I post my inquiry in the wrong place?

giulio's picture

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

gangsongcns's picture

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

giulio's picture

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

Matt's picture

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

giulio's picture

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

Matt's picture

Ok, got it. That works. Thanks so much, Giulio. What would I need to do to add another input for a 'z' slider?

Matt

giulio's picture

Hi Matt, you can right click the middle of the component and choose "Input Manager...".
- Giulio

Matt's picture

Great, that's exactly what I needed.
Thanks again Giulio!

Matt

MSAHLI's picture

Hi

Now that i installed the last version of Rhino5

the Python component for Grasshopper works fine

Thanks

giulio's picture

Thank you, nice to hear this.
- Giulio

Holst's picture

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

giulio's picture

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

MSAHLI's picture

Python component for Grasshopper v 0.4.2.0 does not working !!!

Isent email (screen shot) to david@mcneel.com

giulio's picture

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