Delete Layer?

In Rhino, I can delete a layer by going to the layers tab, right clicking a layer, and choosing delete layer. What is the equivalent of this in Rhinocommon? I’ve tried Doc.Layers.Purge and Doc.Layers.Delete but neither of these seem to do it.

Thanks,
Sam

Does this help?

Interesting, but purge still doesn’t work for me…

Hi @samlochner ,
Another reason why Doc.Layers.Purge may fail (other than that layer being the current layer) is when there are block definitions on that layer.

I have layers with sub layers, not sure if that is what you mean…

This works in Rhino 7:

import Rhino
import scriptcontext as sc

idx = sc.doc.Layers.FindByFullPath("Test", -1)
if idx >= 0:
    sc.doc.Layers.Purge(idx, True)
    sc.doc.Views.Redraw()

In prior versions, you’ll have to delete/purge sublayers individually.

https://mcneel.myjetbrains.com/youtrack/issue/RH-55695

You never mentioned you are trying to delete a layer which has sublayers.
Regardless of that, if you have a block definition on the layer, Purge will fail.

Works now. My mistake was I was trying to use it with layer index…

Thanks,
Sam