[SOLVED] Layer.IsVisible doesn't work

windows
rhinocommon
layers
visibility

#1

Hello,

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.


#2

Do you call for a redraw after the code you’ve shown?


(Menno Deij - van Rijswijk) #3

You must call doc.Layers[i].CommitChanges() to, well, commit your changes :slight_smile:


#4

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.

The problem remains. :confused:


(Menno Deij - van Rijswijk) #6

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.

#7

Yes, this works now! Thank you very much.

This is highly counter-intuitive, and a result of interfacing a C++ SDK from .NET.

I guess you learn something new every day right? :wink:


(Steve Baer) #8

This was a bug we never got around to fixing in V5. I fixed this for V6. You shouldn’t have to call commitchanges on layers in V6