Hi everybody,
I’m trying to “bake a curve” from Grasshopper to Rhino with ghPython. But I’m surprised not to find any function in python to transfer an ordinary curve from gh context to rhino context.
I would have used something like “rs.AddCurve(curve)” but arguments are points and degree for this function.
Does anybody knows a way to achieve this?
Thank you
The only way I found is the following :
points = rs.CurvePoints(curve)
knots = rs.CurveKnots(curve)
degree = rs.CurveDegree(curve)
rs.AddNurbsCurve(points, knots, degree)
There might be a way to do this in once directly from the GUID …
Does anybody have an idea ?
Hi @BaptisteC
you can transfer a curve from the Grasshopper document to the Rhino one like so:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
if active:
curve = rs.coercecurve(c) #from ID to RhinoCommon curve
new_curve = curve.Duplicate() #do not share between docs
rhdoc = Rhino.RhinoDoc.ActiveDoc
rhdoc.Objects.Add(new_curve)
Giulio
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
bake-curve-sample-baptiste.gh (6.0 KB)
Thank you Giulio,
This is exactly what I was searching for.
But I still don’t really get when using rhinoscriptsyntax or other syntax. If you had a quick explanation, I’d be glad to read it.
If you have Guids, that is a very strong indication that you are using RhinoScript. RhinoScript keeps references to objects as IDs (Guids). In turn, objects are stored by ID in a document. The coeceXXX RhinoScript function will look for the type of thing that you specify and give you back the original RhinoCommon geometry.
Please see the help on GhPython. Insert a new GhPython component into the document and click “Help”.
It contains a lot of information. If you feel some is missing, please let me know.
Thanks
Giulio
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
Ok I’ll read this.
Thanks