C# deleted object in Grasshopper

Hi there,
I’ve been playing around with C# grasshopper components to access the document ObjectTable through rhinocommon. Originally I was looking into how blocks work in Rhino. I noticed that when geometry is ‘converted’ into a block, the original geometry is deleted and copied with a new GUID to the objectTable and referenced by the instancedefinition (block).
This got me wondering what other geometry might be stored in the table, but not “visible”. I noticed that deleted geometry stays on the table until the file is closed, saved and reopened. However, at least from within grasshopper, I’m having difficulty getting a list of the deleted geometry.

For example: I start a new Rhino document and draw three rectangles.
I use the following code to count objects on the geotable:

Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;
Print(ot.Count.ToString());
foreach (Rhino.DocObjects.RhinoObject objects in ot.GetObjectList(Rhino.DocObjects.ObjectType.AnyObject)) {
  Print(objects.ObjectType.ToString());
  Print(objects.Id.ToString());
}

and it outputs “3” and “Curve” and the GUID of each curve.
I then delete one of the rectangles, hit F5 and the count still says “3” but the list only shows 2 Curves.
I then use the following, but neither loop returns the deleted geometry:

Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings();
settings.DeletedObjects = true;

Rhino.DocObjects.RhinoObject[] obj = ot.FindByFilter(settings);
for (int i = 0; i < obj.Length; i++) {
  Print(obj[i].Id.ToString());
}
foreach (Rhino.DocObjects.RhinoObject objects in ot.GetObjectList(settings)) {
  Print("   " + objects.Id.ToString());
}

Any suggestions?
As a side note, there is a lot of missing documentation on the rhinocommon site, which isn’t making this exploration any easier! Took me a long time to work out the difference between “InstanceDefinitionTable”, “InstanceObject”, “InstanceReference”, "InstanceDefinition, and “InstanceDefinitions” :smiley:

Thanks,
Steven

Hi @Steven,

This seem to work (albeit Python):

import Rhino
import scriptcontext as sc

settings = Rhino.DocObjects.ObjectEnumeratorSettings()
settings.NormalObjects = False
settings.LockedObjects = False
settings.DeletedObjects = True

objects = sc.doc.Objects.FindByFilter(settings)
if objects:
    for obj in objects:
        print obj.Id

Why do you need this?

Thanks,

– Dale

2 Likes

Thanks @dale,

The python script doesn’t seem to work for me; I get "‘CustomTable’ object has no attribute ‘FindByFilter’
I’m using Rhino6sr23 and GH 1.0.0007

However, when I add in the NormalObjects = false and LockedObjects = false to my C# code, it now returns the deleted objects. It requires both to be set false before the deleted one returns the list.
The documentation here doesn’t explain any of this though:
https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_ObjectEnumeratorSettings.htm
and also points me to: Rhino.Collections.ObjectTable.GetEnumerator()
which I guess is actually now in: Rhino.DocObjects.Tables.ObjectTable.GetEnumerator ?

Are you able to elaborate a bit more on why some of the settings parameters need to be set, but not others?
I don’t need this for anything specific, I’m just poking around under the hood to get a better understanding of how Rhino works. Is there a better resource for learning about rhinocommon than https://developer.rhino3d.com/api/RhinoCommon/?

Thanks again,
Steven

Hi Steven,

If you are using ghpython component in grasshopper, replace sc.doc with Rhino.RhinoDoc.ActiveDoc.

1 Like

Thanks @djordje, yep that works. You can tell I don’t usually use python! :smiley: