Delete a range of layers

Hi,
I want delete a range of layers via code. But not one by one with a loop, this is way to slow.
When we manually select a range of layer in rhino, and the press on the red cross button it deletes very fastly all the selected layers. But how to have the same efficiency in a script ?

  • I don’t find a method in the API that takes a list of layer. Something like this : LayerTable.Purge(IEnumerable layerIndices)
  • I don’t find a command to launch in rhinoScript. There is the “-Layer Delete” but it sends to an interface to select the layers, and i don’t know ho to address it.

Any idea ?

I don’t really see how looping through a list of layers and deleting them one by one would be significantly slower than a mass delete of a list of layers - unless, you did not disable the redraw while looping, in which case it will redraw the screen after each layer delete, and that will be slower.

You also need to worry about layers with objects on them, parents of sublayers, etc.

Ok I see. Indeed i just tried with adding these lines at the start and end of the script, and it is way faster!

Rhino.RhinoDoc.ActiveDoc.Views.EnableRedraw(false, false, false);
Rhino.RhinoDoc.ActiveDoc.Views.EnableRedraw(true, true, true);

Thank you Helvetosaur