LayerTableEvent when deleting a layer

Hi all,

When I am deleting a layer I am getting an event of type Rhino.DocObjects.Tables.LayerTableEventType.Deleted

In the arguments I can see the parent layer of the deleted one as NewState and null for the OldState.

Is there any way to receive the actual deleted layer in the arguments? Maybe some other event?
I would like to avoid searching in the child layers of the NewState layer the missing one from my data structure, so I delete it from there as well.


Hi @Aitor, does e.LayerIndex give you that information ? It seems to work here.

btw. i’ve changed the topic to Rhino Developer.

Hi Clement,

I have just tried to get LayerIndex to fetch the layer from Rhino.RhinoDoc.ActiveDoc.Layers.

I still get the parent layer. Even more, I am getting child layers with GetChildren() and I am not getting the rest of the child layers.

Using RhinoCommon for Rhino 6

@Aitor, you’re right, below works fine to get the deleted layer name in Rhino 5:

layer_name = scriptcontext.doc.Layers[e.LayerIndex].Name

but in Rhino 6 it returns None, same as e.OldState. Imho this feels buggy.


Fair enough. I will wait for the update then :).

Hi @Aitor,

With layer table events, the LayerTableEventArgs.OldState property will only be non-null in the case of LayerTableEventType.Modified events.

Let me know if this helps.

– Dale

Hi @dale,

The issue is that I want to get the actual deleted layer in the event info. I cannot.
When I check the layer table I cannot even find child layers of the parent of the deleted one.

“layer1 has layer11 and layer12. I delete layer12 I get layer1 in the deleted event information. When I check the layer1 children layer11 is not there either”. This looks like a bug.

Hi @Aitor,

Because the name used by a deleted component, such as layers, is legitimate as a name for a new active component, and no two components can have the same name, deleted components loose their name.

In the Visual Studio debugger, look at e.NewState. Notice now the Index and Id properties are correct? Also notice how the Name property is null?

What is missing from the Layer class is a way of retrieving the name of the layer if the layer is deleted. I’ve added a new DeletedName property for Rhino 6 SR2 that should help with this.


– Dale

Hi @dale
When do you think SR2 for Rhino 6 will be released?


According to this post, that will be in about 5 weeks. I take it that Release Candidates should be available before that.

Good to know.

Thanks @wim.

RH-43947 is fixed in the latest Service Relase Candidate

1 Like

Working. Thanks guys.