RhinoPython - Create object, but don't add to scene (or remove it afterwards)

I have tried looking for an answer to this question but wasn’t able to find it. Sorry if it is a duplicate, which I think it is.

I’m trying to automate the modeling of a geometry and make it depend on a set of initial parameters that can be set by the user. However, creating the final geometry requires creating a few intermediate curves and points etc. Can I prevent Rhino from adding those objects to the final scene? Or is there an easy way to remove them after they have served their use?

Please note that I don’t want to do any clicking in the viewport to obtain the GUID’s of the objects, the script has to run from beginning to end without user interference. It should function as a built the entire thing button.

Hello - yes, that is, you can make and manipulate geometry that is not in the document using RhinoCommon but not if you stick to rhinoscriptsyntax methods.

-Pascal

OK. Good to know, I’ve been searching through the wrong API then. Onwards to RhinoCommon it is! Thanks. As a follow up question: Does the same hold true for deleting objects from the scene? Or is there a programmatic way to remove objects?

If the objects are in the file, they have a GUID, you can delete them by rs.DeleteObject(ID) or rs.DeleteObjects(list of IDs)

HTH, --Mitch

Yes, but what I’m missing is how to obtain those GUID’s selectively? All I can find is the AllObjects() functionality which I should then filter to get the right objects, but that’s tricky.

Is the GUID also a component of the object in the code? i.e.:

some math generating airfoil coordinates X and Z

airfoilPoints = []
for x, z in zip(X,Z):
    airfoilPoints.append([x,0,z])

airfoilCurve = rs.AddCurve(airfoilPoints,3)
do other stuff
rs.DeleteObject(airfoilCurve.guid)

I hope I’m explaining myself properly

If you are adding the curve using rs.AddCurve then the variable ‘airfoilcurve’ IS a GUID (well, a GUID-like string) and you can use it directly when needed:

rs.DeleteObject(airfoilcurve)

It helps to run the script with some break points in the de-bugger so you can see what the variables are. When rs adds an object(s) the return is either a GUID or a list of them.

-Pascal

Oh that’s weird! I tried that and it didn’t work. I’ll try again then.
O man. That does work. I feel silly now haha. Must have mistyped something. Thanks for the help guys. I’ll also need to have a look at RhinoCommon. This is a very powerful tool!