Setting one layer to invisible

Suppose I’ve got layer 1, 2 and 3 set to visible and I want to make layer 1 invisible. I thought that could be done by:


import Blender
from Blender import*
test = Blender.Window.ViewLayer()
test2 = test.remove([1])
Blender.Window.ViewLayer(test2)

Unfortunately I get the error:


ValueError: list.remove(x): x not in list

However, when checking the value of ‘test’, with print(test), it returns:


[1, 2, 3]

so 1 is in the list.

Does anybody have an idea?
One more question; does anybody know how to check whether a certain value is in a list (in case the layer is already set to invisible)?

[1] is a list with one element. where as test has three elements [1, 2, 3]

so saying [1] does not make sense. although you could have extracted the element one by saying test[0] which is 1.

to test if an element is in a list you can use


software = ["blender", "wings3d", "gimp"]

if "blender" in software:
    print "Wooooooo Hooooooo"

Here is the corrected code [i have a habit of commenting code]


import Blender
from Blender import *

# get a list of all visible layers
test = Blender.Window.ViewLayer()
# now we have test = [1, 2, 3]

# remove layer number 1, if present, from the list
if 1 in test:
    test.remove(1)
# now we have test = [2, 3]

# let the 3dwindow show the layers in "test"
Blender.Window.ViewLayer(test) 

# Redraw the 3d window
Blendr.Redraw()

hope that answers all your questions.

Thanks a lot for the fast and clear reply.
It does indeed answer my questions.

No Problem Crouch.

Happy Hacking.