How to clear the layer table?

Hi,

I am using the layers to add different geometries to different layers.
After I delete several layers and I found the count of the layers is unchanged.
The deleted layers seems remained except the geometries in layers.
My questions is : how to delete the layers entirely or how to delete the layers in layer table?

Thanks

Kalvin

Hi @hearts_j,

If you want to delete a layer, you first must either move or delete the objects that reference that layer.

Also, reference layers - layers from referenced worksession files or linked blocks - cannot be deleted.

Does this help?

– Dale

1 Like

Hi @dale

I understand your method,Actually,I did a test to repeat the

1.I creat 20 layers by coding,the 20 layers can be seen in the layer dialog. (Rhino.RhinoDoc.ActiveDoc.Layers.Add(layer))
2.I delete 20 layers,the 20 layers just created in the last stepdisappeared in the layer dialog .(RhinoDoc.ActiveDoc.Layers.Purge(i, True) or RhinoDoc.ActiveDoc.Layers.Delete(i, True))
3.When I check the layers count,It still returns 20.( Rhino.RhinoDoc.ActiveDoc.Layers.Count)
4.Repeat several times add and delete processing(different layers number),the count of layer only can be increasing but decreasing.After that I can’t get the correcting index of the layer.
5.So I guess the layer table can’t be delete.Is that right? If I want to make each layer corresponding with my slicing layer of the model,how to make it?

Thanks

Kalvin

Rhino really never deletes anything. It just tags objects as deleted. This way, the operations can be undone by running the Undo command.

Note, objects that are marked as deleted are not written to the 3dm file. I guess you could say this is where the actual deletion occurs.

Layers.Count returns the total number of layers, included deleted layers.

http://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_DocObjects_Tables_LayerTable_Count.htm

Does this help?

– Dale

@hearts_j, in addition to Dale’s response above, you might try:

Rhino.RhinoDoc.ActiveDoc.Layers.ActiveCount

it returns the layers, but excludes the deleted ones.

_
c.

@clement

Yes ,It’s a another way.
Problem solved, though not perfect,but not bad. :wink:

Thanks

Kalvin