I would like to Purge some objects from my Rhino file. Some Breps are created recursively and when I manually delete them in the RhinoDoc and rerun the code they don’t get baked again.
Is it correct in understanding that this happens because they have the same GUID as the previous ones?
Anyhow, the code I am running is:
Error (CS0120): An object reference is required for the non-static field, method, or property ‘Rhino.DocObjects.Tables.ObjectTable.Purge(uint)’
Error (CS0120): An object reference is required for the non-static field, method, or property ‘Rhino.DocObjects.Tables.ObjectTable.Purge(Rhino.DocObjects.RhinoObject)’
Is it not possible to purge after deleting? (even though rhino is finding all of their ids)
If you look at ObjectTable.Purge Method you will see that it is an instance method, so you need to call it on a document object table instance. In your example code you have a document instance in doc, so call Purge on its Objects property: doc.Objects.Purge(rhinoOb).
The first one that takes an uint32 takes a serial number of the object you want to purge from the document (ObjectTable.Purge Method (UInt32)). You pass it the document serial number, which is incorrect.
using Rhino.DocObjects;
RhinoObject[] rhinoObjects = doc.Objects.FindByObjectType(ObjectType.Brep);
foreach(RhinoObject bb in rhinoObjects)
{
doc.Objects.Purge(bb);
}
Naturally, if you want to delete only certain objects you need to ensure that your rhinoObjects array contains only those RhinoObjects you want to permanently delete without them being in the undo list.
Thank you so much!
Follow up question: How do I find an object’s uint32?
The overkill~another not particularly rhino related: I am not quite getting the “instance of an object” meaning. Do you happen to know of any documentation/ tutorial that clearly explains it?
Word of warning: note that this is a number you should not save between sessions. As the name tries to tell: it is valid only during that session.
When I say instance in this thread I mean an instance of a class. So we had in this thread already: RhinoDoc, RhinoObject and ObjectTable as classes, and to use the non-static methods these classes provide you need instances of such classes to do so.
If you implement a command in a custom Rhino plug-in in C# you’ll be overriding the method RunCommand, which as one of its parameters will have RhinoDoc doc. You get a variable with the name doc that points to an instance of a RhinoDoc. Likewise the Objects property on RhinoDoc will give you access to an instance of an ObjectTable.