I’m developing a c# plugin and I use ForceLayerVisible to make all layers visible.
But I don’t understand why I encounter “deleted layers” in a referenced linked file.
I must check if the layer is not deleted to pass it to ForceLayerVisible.
Is it normal ?
Would ForceLayerVisible check this internally ?
foreach (Rhino.DocObjects.Layer layer in Rhino.RhinoDoc.ActiveDoc.Layers)
if (!layer.IsDeleted) // Crash if not checked
Rhino.RhinoDoc.ActiveDoc.Layers.ForceLayerVisible(layer.Id);
And I would like to know the purpose of layers declared “deleted”.
I thought maybe it has something to do with undo but it is saved in the file.
Maybe it has nothing to do with deleted layers.
The name of the layer making ForceLayerVisible to crash is null.
What property should I check to avoid invalid layers ?
In the mean time, just check to see if the layer is deleted first:
import Rhino
import scriptcontext as sc
for layer in sc.doc.Layers:
if not layer.IsDeleted:
print('{0}'.format(layer.FullPath))
sc.doc.Layers.ForceLayerVisible(layer.Id)