I am having issues with turning the visibility of all my layers off (except the default one).
So in my main function I do a lot of things including adding new layers, childlayers, adding objects to these layers and changing properties as well. Then after everything, but before doc.Views.Redraw(); I do the following, which sadly doesn’t work:
for (int i = 1; i < doc.Layers.Count; i++)
{
doc.Layers[i].IsVisible = false;
}
Not one layers has been turned invisible. What is wrong with that code? Can someone help how to do it correctly? (I program a C# Rhino Plug-In for Windows.)
Thanks.
Makes sense, I added that now, but still no layer is turned invisible. Weird right? Does it have to do with childlayers? I turn IsVisible = false for every layer though so that shouldn’t be a reason.
Oh I did something wrong in my example earlier, sorry! You need to use the same instance of the layer that you get from the Layer table. Every time you get a layer using doc.Layers[i] a new instance of a Layer object is created for you. This is highly counter-intuitive, and a result of interfacing a C++ SDK from .NET. So, having said that, I wonder if this works better:
for(int i = 1; i < doc.Layers.Count; ++i)
{
Layer l = doc.Layers[i];
l.IsVisible = false;
l.CommitChanges(); // commit changes ON THE SAME INSTANCE
}
Test for instance equality:
Layer lay_zero = doc.Layers[0];
Layer lay_zero_too = doc.Layers[0];
Debug.Assert(ReferenceEquals(lay_zero, lay_zero_too)); // this will fail.