Grasshopper

algorithmic modeling for Rhino

Thanks to Steve and Giulio, a new version (0.6.0.3) of the ghPython scripting component for Grasshopper is available on food4Rhino

Major new features:.

  • Node-in-Code: almost every Grasshopper component is now callable in ghPython

  • Multi-threading: now easy for ghPython scripts to execute on multiple threads

Download here...

Views: 5694

Replies to This Discussion

Works great, thanks!

I had no idea I had to do that. Are there any sources I could read to get to know more about python scripting in Rhino?

Cheers

Yes, there are but mostly related to scripting in Rhino Python Editor.
Check the Rhino Python primer and tutorials from Mcneel's wiki website.

Here I am again,

I'm sorry I'm hijacking the thread to solve this, but it really seems bizarre as I can't explain what's going on. The line I generate inside the python script seems fine but it doesn't generate any output compared to a line I supply in the inputs?? Is there some generic typecast I am missing?

Hi Arturs,

You are using a rhinoscriptsyntax function AddLine() to generate your line. This function returns a guid (an object identifier), whereas your ghpythonlib.component function EvaluateLength requires curve object, as it's first argument. Take a look at this discussion, somewhat similar questions appeared there.
So what needs to be done is to feed the guid of your _line curve into the rs.coercecurve() function, in order to create a curve object. Then feed that into ghcomp.EvaluateCurve:

import rhinoscriptsyntax as rs
import scriptcontext
import ghpythonlib.components as ghcomp

_line = rs.AddLine(y,z)
line_object = rs.coercecurve(_line)

b = ghcomp.EvaluateLength(u,0.5).point

a = _line

c = ghcomp.EvaluateLength(line_object,0.3).point


You can also try not to puzzle yourself whether you are supplying guid or an object, by simply using a ghcomp function for creating a line, instead of rhinoscriptsyntax AddLine one:

import rhinoscriptsyntax as rs
import scriptcontext
import ghpythonlib.components as ghcomp

_line = ghcomp.Line(y,z)

b = ghcomp.EvaluateLength(u,0.5).point

a = _line

c = ghcomp.EvaluateLength(_line,0.3).point

Please attach your files for future questions.

Awesome, thank you.
It's not easy to find tutorials on this subject as google mostly churns out info on python in general.

Have a great holiday, djordje!

Agree with that. There should be an error message, that supplied data is not of a required type.

@ Arturs Tols:
Thank you. You too.

I don't know if this is the place to post this. I am very exited about this new functions. But I recently noticed that the gh.SurfaceClosestPt seems to be working a lot slower than by using rhinoscriptsyntax, where one has to use 3 commands if you want to get the point and the distance.

(That's how I do it any way - rs.SurfaceClosestPoint - rs.EvaluateSurface - rs.Distance)

There might be a really good explanation, but I was just wondering if it might be a bug?

Hi there,

I am trying to use the "Group Points by distance" command with ghpython.
The ghcomp.PointGroups manages to order the list of points I am feeding it, however it does not create sub-lists (branches) for each group.

In the image below, the panel on the left is from the ghcomp script, while on the right it is using standard gh components. I would like to do this within ghpython if possible. As the image displays, the script is working well, however I need to have nested lists in order to make any use of the command.

Any advice would be greatly appreciated!

I have also posted this same question on the Rhino Forum.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service