Bake and delete objects in Rhino with RhinoCommon

A very basic implementation of baking and deleting objects in Rhino through Grasshopper.

Rhino ObjectTable

Rhino objects are accessed through the object table – a container object which holds information about all objects in a Rhino document.

Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;

Add an object

Within the ObjectTable is a range of methods for adding objects. There is a method for each kind of geometry (meshes, lines, points and so on).

For example, to add a line:

ot.AddLine(new Point3d(0, 0, 0), new Point3d(1, 1, 1));

Deleting the most recent object

The Object Table appears to be sorted in order that objects were added, most recent first. So, to delete the most recent object, we need to delete object 0:

//get guid of the most recent object
Guid id = ot.ElementAt(0).Id;

//deletes this object
if(z) ot.Delete(id, true);

Get the number of objects

Unless there’s a better way to do it, the method below works. This returns the number of objects in the object table.

var sf = new Rhino.DocObjects.ObjectEnumeratorSettings();
int count = ot.ObjectCount(sf);

References

One thought on “Bake and delete objects in Rhino with RhinoCommon”

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: