Isotropix Forums

Python: get visible layer names

Clarisse Scripting related topics

Python: get visible layer names

Unread postby iEatPuppies » Thu Oct 12, 2017 12:39 am

Hello all. I am trying to get a list of all layers that have their visibility turned off.

I have an image in my project that I have selected, and this image has 4 different render layers within it. With Python, I am trying to figure out which ones are set to visible and which ones are not...

When I toggle the visibility(eye) icon on my Background layer, I can see the python command in my log.

ix.cmds.DisableAttributeValue(["project://image.layers"], [0], False)


How can I directly read this attribute instead of modifying it?


Thanks in advance!
Ali
Attachments
clarisse_get_visible_layer_names_python.jpg
Alican Sesli
Compositing TD
LUX Visual Effects
User avatar
iEatPuppies
 
Posts: 4
Joined: Fri Mar 03, 2017 4:28 am
Location: Vanocuver

Re: Python: get visible layer names

Unread postby bvaldes » Thu Oct 12, 2017 10:14 am

Hi,

There is a sample of code to achieve your goals:

python code

def getDisabledLayers(image):
image = ix.get_item(image) # If the user give a string in argument, we have to transform it into a Clarisse's item
layerDisabled = [] # Will contain all the layer that have the visibility turn off
all_layers = image.get_module().get_all_layers() # get the list of all layers

for i in range(all_layers.get_count()):
layerItem = image.get_module().get_layers()[i].get_object() # The layer item

# To know if the layer is disabled or not, we have to look at the "layers" attribute of the image.
# If we try to get an item that is disabled, the command will return None
# If the command return None, we can add the item to the list
if isinstance(image.get_attribute("layers").get_object(i), type(None)):
layerDisabled.append(layerItem)

return layerDisabled

print getDisabledLayers("project://scene/image")


This function takes as argument the path of the image that you want to check the layers visibility. It returns a list of the turn off layers. You can see in attachment an image that demonstrates the result.

I hope that will help you. If you need more information feel free to ask.

Regards.
Attachments
Screen Shot 2017-10-12 at 10.09.50.png
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 160
Joined: Mon Sep 26, 2016 11:44 am

Re: Python: get visible layer names

Unread postby iEatPuppies » Thu Oct 12, 2017 10:48 pm

..Exactly what I wanted, thank you very much!
Alican Sesli
Compositing TD
LUX Visual Effects
User avatar
iEatPuppies
 
Posts: 4
Joined: Fri Mar 03, 2017 4:28 am
Location: Vanocuver


Return to Scripting