algorithmic modeling for Rhino
Hi,
A couple of friends and I have been trying to output a nested list of geometries ( polylines) from the Grasshopper/python editor to grasshopper keeping the data structure. I know I have to work with GH_Path to create Data trees but the problem seems to be that the type of geometries dont match.
I get this error:
Runtime error (ArgumentTypeException): expected Polyline, got Guid
event though the GUID object comes from a rs.AddPolyline command.
I have stated that the type of geometry in the GH tree is Polyline using this:
gh.DataTree[Rhino.Geometry.Polyline]()
What type of polyline is GH expecting?
It seems we are all having troubles translating branched data from python to grasshopper.
I attach the definition just in case
Thank you in advance
Federico
Tags:
As far as I can tell the rs.AddPolyline() function returns the ID of the new curve object. In which case you could use the rs.coercecurve() function to get the curve object from this ID, or, create the polyline using RhinoCommon to begin with. Again, I think. Haven't tested this out..
Hi Anders,
Thanks for your answer. I used rs.coercecurve() and now the error is this:
expected IEnumerable[Polyline], got PolylineCurve
What is IEnumerable?
Also, if I wanted to try creating the polyline using RhinoCommon, what would the commands be? Rhino.Geometry.Polyline? that doesnt seem to work
Thanks again!
F
Regarding IEnumerable check out this thread might help:
http://www.grasshopper3d.com/forum/topics/network-surface-error-pyt...
Regarding using Rhino.Geometry.Polyline the help file suggests that you need to feed it a list of points. See the constructors here:
http://www.rhino3d.com/5/rhinocommon/html/AllMembers_T_Rhino_Geomet....
Alternatively you can create an "empty" polyline and then use its method for adding points, see this:
http://www.rhino3d.com/5/rhinocommon/html/M_Rhino_Collections_Point...
In general I try to avoid dealing with GH datatrees. I think Giulio suggested this at some point as well. Tends to become a bit "iffy" I find. That said it probably is very powerful and useful.
I just had a bit of a fiddle with the creation of polylines. Turns out that there are both Polyline and PolyLineCurve. The first being just an ordered set of points and the latter an actual polyline/curve. Here's an example:
import Rhino as rc
# Create a list of points
points = [rc.Geometry.Point3d(0,0,0),rc.Geometry.Point3d(10,10,0),rc.Geometry.Point3d(30,0,0)]
# Create a polyline from these points (this is basically an ordered set of points!)
polyline = rc.Geometry.Polyline(points)
print type(polyline)
# But you can get the segments from this polyline as an array of lines
segments = polyline.GetSegments()
print type(segments)
# Or simple create a polylinecurve directly
polylinecurve = rc.Geometry.PolylineCurve(points)
print type(polylinecurve)
Ps. Does anybody know how to post source here on the forum. Tried Googling it as well as searching here without much luck!
Hi NAdres,
Thanks so much for your time. IT is solved now and working smoothly. Im using PolylineCurve.
cheers!
Federico
Excellent, glad that it worked out :)
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by