Working with curve in python in grasshopper

I’m trying to do something that seems that ought to be simple but not making progress. I have a file (16.7 KB)
that is creating a certain curve. I have used an object to create a list of x,y points and have sent that to an object to create a nurbs curve. The output of the nurbs curve is a curve. I would like to get the curve guid id and work with the curve inside a python math block. All the examples I have in Python for Rhinoceros 5 requires that I select a curve. In this case I don’t want to have to select a curve. I have the curve I want to work with, the output of the nurbs object. When I test the code it prints out something that looks kinda sorta like a guid but when I ask if it is a curve it appears not to be. The final goal here eventually is to be able to bake the curve but do it from a button on my HumanUI panel. I don’t want to have to bring up the grasshopper pane and select the nurbs object and right click to bake.
Edited a couple of hours later. I think I solved my puzzle by giving the thing a hint about the type input to the python block. Now that I hinted it was a curve, I’m getting somewhere.

But now after a little more work, I still need help. Here’s the latest file (10.3 KB)
I’ve essentially copied code from page 43 of Python for Rhinoceros 5 where a nurbs curve is added. But the curve does not show up in Rhino. I must still be doing something dumb.

You need to assign your curve to an output to see and/or bake it.

Just add this line to the bottom of your code:

a = newcurve_id (20.0 KB)


Thanks. That makes sense. But I did that and the curve still disappears when I close grasshopper. I’d still have to right click on the python block and click “bake” to get the curve to persist in Rhino.

Yes at that point it is just like any grasshopper geometry - you will have to bake it to have it persist in Rhino after you close grasshopper.

In your initial post you wrote:

That would be one option.

As another option here is a code example that shows how to bake geometry from a GhPython script.


Many thanks for that link. I had not found that. I did change my program to the following (16.2 KB)
And it did work one time. But afterward I got error messages that it expected UInt and got a nurbs curve.??
Could not get it to work after that.

Okay. A couple hours later I developed a version that seems to work for me each time. I wish I understood better the why and how of the classes of Rhino, but I do understand why I had to switch the contexts from gh to Rhino and back. Anyway, here’s my final version that I’ll keep in my toolbox. (12.1 KB)
Many thanks for pointing me to the Baking thing. Couldn’t have done it without that.