Isotropix Forums

Query if a Channel layer is in use.

Clarisse Scripting related topics

Query if a Channel layer is in use.

Unread postby stheroux » Fri Nov 15, 2019 3:40 am

Hello,

When in the AOV editor, there is a visual indication (shade of grey) of whether a channel layer is in use or not in a 3d layer.
Is there a way to get that info in python?

Thanks
Sylvain
stheroux
 
Posts: 90
Joined: Thu Jan 15, 2015 9:23 pm

Re: Query if a Channel layer is in use.

Unread postby anemoff » Fri Nov 15, 2019 2:41 pm

Hi,

Here are a couple of helper functions to do so:

python code

def get_layer3d(image_item, layer_name):
"""Get the Layer3d named `layer_name` in the given image item, or None if not found."""
layers = image_item.get_module().get_layers()
for i in range(layers.get_count()):
layer_obj = layers[i].get_object()
if layer_obj.is_kindof('Layer3d') and layer_obj.get_name() == layer_name:
return layer_obj

ix.log_warning('No Layer3d named "{}" in image "{}"'.format(layer_name, image.get_full_name()))
return None

def get_aovs(layer3d_obj):
"""Get all AOVs names present in the given Layer3d object, including disabled."""
aovs = ix.api.CoreStringArray()
layer3d_obj.get_attribute('selected_aov_list').get_values(aovs)
return aovs

def is_aov_enabled(layer3d_obj, aov_name):
"""Query if the given AOV is enabled in the Layer3d."""
aovs = get_aovs(layer3d_obj)
if aovs.exists(aov_name):
aov_index = aovs.get_index(aov_name)
enabled_values = ix.api.BoolArray()
layer3d_obj.get_attribute('enabled_aov_list').get_values(enabled_values)
assert aov_index < enabled_values.get_count()
return enabled_values[aov_index]

ix.log_warning('AOV "{}" not found in Layer3d "{}".'.format(aov_name, layer3d_obj.get_full_name()))
return False

# Usage example
image = ix.get_item('project://scene/image')
layer3d_obj = get_layer3d(image, 'background')
if layer3d_obj:
# Print all aov names and their enabled status
aovs = get_aovs(layer3d_obj)
ix.log_info('{} AOV(s) in Layer3d "{}"'.format(aovs.get_count(), layer3d_obj.get_full_name()))
for aov in aovs:
ix.log_info('- "{}": enabled = {}'.format(aov, is_aov_enabled(layer3d_obj, aov)))


You might want to also take a look at the following SDK pages:
- https://www.clarissewiki.com/4.0/sdk/cl ... nager.html
- https://www.clarissewiki.com/4.0/sdk/cl ... layer.html
- https://www.clarissewiki.com/4.0/sdk/cl ... yer3d.html

I hope it helps.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 306
Joined: Wed Jan 13, 2016 10:10 am

Re: Query if a Channel layer is in use.

Unread postby anemoff » Fri Nov 15, 2019 2:46 pm

Or do you mean globally, across all images in the current project?
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 306
Joined: Wed Jan 13, 2016 10:10 am

Re: Query if a Channel layer is in use.

Unread postby stheroux » Fri Nov 15, 2019 4:30 pm

Hi Anthony,

Thanks for that I'll have a look. Just as a side note, searching for channel manager in my local doc of 4.0sp3 yields no result (nor channelmanager, channelmanager or any of its member). If i paste the url directly in my local doc it works so might be an search index issue?

Anyway, thanks for the doc, should be easier then help() and dir()
Sylvain
stheroux
 
Posts: 90
Joined: Thu Jan 15, 2015 9:23 pm

Re: Query if a Channel layer is in use.

Unread postby stheroux » Fri Nov 15, 2019 4:41 pm

I will need it globally, but i can go through all my images layers and keep track of whats in use.

But am i wrong in thinking this code will return aovs even if there are greyed out, as long as they are selected and enabled ? I somehow thought the enabled status only refer to the little visiblilty "eye"?
stheroux
 
Posts: 90
Joined: Thu Jan 15, 2015 9:23 pm

Re: Query if a Channel layer is in use.

Unread postby anemoff » Fri Nov 15, 2019 4:55 pm

Indeed, the search engine from the SDK doc has limitations. It seems it doesn't do sub-string search. The real class name is OfChannelManager: if you type "ofchannel" it will show, but "channel" won't. We'll take note of this for future improvements if possible.
A workaround is to go to the "Classes" page and do a Ctrl + F with the web browser text search: https://www.clarissewiki.com/4.0/sdk/annotated.html

Yes, you can use the helper functions and run them on all the images.

In the functions above, "get_aovs" will indeed return all AOVs, even disabled ones. And yes, the eye shows the enabled status.
You could add a helper like this, to get only the enabled ones:

python code

def get_enabled_aovs(layer3d_obj):
"""Get all the names of AOVs that are enabled in the given Layer3d (eye icon enabled)."""
enabled_values = ix.api.BoolArray()
layer3d_obj.get_attribute('enabled_aov_list').get_values(enabled_values)
aovs = get_aovs(layer3d_obj)
enabled_names = []
for i in range(enabled_values.get_count()):
if enabled_values[i] == True:
enabled_names.append(aovs[i])
return enabled_names

# Usage example
image = ix.get_item('project://scene/image')
layer_name = 'background'
layer3d_obj = get_layer3d(image, layer_name)
if layer3d_obj:
ix.log_info('Enabled AOVs:')
ix.log_info(get_enabled_aovs(layer3d_obj))


The attribute "selected_aov_list" contains the names of all AOVs, including disabled ones.
The attribute "enabled_aov_list" contains the enabled status of all AOVs: True if enabled, False otherwise. It has the same size as "selected_aov_list".
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 306
Joined: Wed Jan 13, 2016 10:10 am

Re: Query if a Channel layer is in use.

Unread postby stheroux » Fri Nov 15, 2019 5:07 pm

But the fact that an aov is both selected and enabled does not tell me if its actually outputting something (greyed out) ? Thats the info i'm after.
Thanks
Attachments
aovs_greyed_out.JPG
aovs_greyed_out.JPG (12.84 KiB) Viewed 1791 times
stheroux
 
Posts: 90
Joined: Thu Jan 15, 2015 9:23 pm

Re: Query if a Channel layer is in use.

Unread postby anemoff » Fri Nov 15, 2019 5:43 pm

Ah yes, my bad. Here you go:

python code

def get_unavailable_aovs(layer3d_obj):
# get all added AOVs
added_aov_names = get_aovs(layer3d_obj)

# get all AOVs that can output data, including un-added AOVs (super-set of added AOVs)
available_aov_ids = layer3d_obj.get_module().get_available_aovs()

# now, build the list of aovs that are added but unavailable
cm = ix.application.get_channel_manager()
unavailable_aovs = []
for aov_name in added_aov_names:
aov_id = cm.get_layer_index(aov_name)
if available_aov_ids.exists(aov_id) == False:
unavailable_aovs.append(aov_name)

return unavailable_aovs


You can easily adapt it or create a new one to return only the available ones too.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 306
Joined: Wed Jan 13, 2016 10:10 am

Re: Query if a Channel layer is in use.

Unread postby stheroux » Fri Nov 15, 2019 5:49 pm

Great, exactly what I'm after.
Thanks for the help
Sylvain
stheroux
 
Posts: 90
Joined: Thu Jan 15, 2015 9:23 pm


Return to Scripting