Currently I am deleting all objects from a layer using the following C++ code in my DLL:
// Get child layer.
const CRhinoLayer& Layer = layer_table[children[i]];
// Get all objects on the layer.
ON_SimpleArray<CRhinoObject*> objects;
pDoc->LookupObject(Layer, objects);
// Delete all objects on the layer.
for (int32_t j = 0; j < objects.Count(); j++) {
pDoc->PurgeObject(objects[j]);
}
After all the geometry has been removed from all layers, then the layers can be deleted.
However the online documentation for LookupObject says this is an Obsolete function:
It suggests using other functions but I do not understand how to accomplish the same thing.
Any suggestion for a more modern approach or shall I just keep things the way they are?
The need to delete all layers arose when re-running my DLL with the same input file. The first run found 100,000+ issues (duplicate vertices, non-manifold edges, intersecting faces, etc) which are put on separate layers for inspection. To make it easy to select a face that has been highlighted with 3 colored curves, the curves are placed in a group which is placed on a layer. When the Python script that calls the DLL is done, many of the Rhino elements are deleted but not groups. If the Python script is run again, it is 100X slower because the 100,000’s of groups is bogging it down. So before the DLL starts processing the same file again, all groups created by the prior run are deleted at the start. But this takes over 1000 sec! However, I discovered if I purged all the geometry from all the layers for this file, then the groups can be deleted in 0.04 sec. So this is why I need to delete all layers associated with the file. I have finished the code and it is fast and I hope it is working correctly but there is this one outstanding issue (obsolete function) that I want to close out.
Regards,
Terry.