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
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.
Rhino never really deletes anything. Rather, it tags items as deleted, which can help with undo. Deleted items are never saved to 3dm files.
I don’t quite understand what are reporting. Can you help us reproduce what you are seeing?
Run python script within linked_sphere.3dm with sphere.3dm in the same folder.
I inserted sphere.3dm this way :
linked_sphere.3dm (52.4 KB) sphere.3dm (265.4 KB)
force_visible.py (264 Bytes)
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 ?
Thanks - this was really helpful. I’ve logged the bug.
In the mean time, just check to see if the layer is deleted first:
import scriptcontext as sc
for layer in sc.doc.Layers:
if not layer.IsDeleted: