Isotropix Forums

How to remove AOV for image

Clarisse Scripting related topics

How to remove AOV for image

Unread postby stepanyantg » Thu Sep 30, 2021 3:06 am

Hi ,
Could you please give an example how to remove an existing AOV from image?

Thanks,
Tigran
stepanyantg
 
Posts: 2
Joined: Wed May 15, 2019 3:48 pm

Re: How to remove AOV for image

Unread postby anemoff » Thu Sep 30, 2021 10:29 am

Hi,

Do you want to do it by script?

If yes, here is a script I wrote a while ago. Hope it helps.

py code

def remove_layer_aovs(layer3d, remove=[]):
"""
Remove AOVs specified by `remove` from the Layer3D, except the AOVs specified by in `ignore`.

Parameters
----------
layer3d: Layer3d
> The Layer3d to process.

remove: list
> List of AOV names to be removed.

Returns True if at least 1 AOV was removed, False if 0.
"""

if layer3d.is_kindof('Layer3D'):
ix.log_warning('"{}" is not a Layer3D.'.format(layer3d.get_full_name()))
return False

if not remove:
return False # Nothing to remove

# Get current AOVs
# These 3 attributes work together

aov_attr = layer3d.get_attribute('selected_aov_list')
current_aovs = ix.api.CoreStringArray()
aov_attr.get_values(current_aovs)

aov_enabled_attr = layer3d.get_attribute('enabled_aov_list')
current_enabled = ix.api.BoolArray()
aov_enabled_attr.get_values(current_enabled)

aov_blend_attr = layer3d.get_attribute('aov_blend_override_list')
current_blend = ix.api.LongArray()
aov_blend_attr.get_values(current_blend)

# Build the list of AOVs to remove: all values must be specified as strings
new_aovs = ix.api.CoreStringVector()
new_enabled = ix.api.CoreStringVector()
new_blend = ix.api.CoreStringVector()

aov_count = current_aovs.get_count()
for i in range(aov_count):
if current_aovs[i] not in remove:
new_aovs.add(current_aovs[i])
new_enabled.add("{}".format(int(current_enabled[i]))) # convert boolean to 0 or 1
new_blend.add("{}".format(current_blend[i]))

if len(new_aovs) == 0:
return False # Nothing to remove

# Remove the AOVs
print('{}: found {} AOVs to remove.'.format(layer3d.get_full_name(), new_aovs.get_count()))
ix.begin_command_batch('Remove Layer3D AOVs')
ix.cmds.SetValue(aov_attr.get_full_name(), new_aovs)
ix.cmds.SetValue(aov_enabled_attr.get_full_name(), new_enabled)
ix.cmds.SetValue(aov_blend_attr.get_full_name(), new_blend)
ix.end_command_batch()

return True

# Run it
layer3d = ix.selection[0]
remove = ['rgba']
something_removed = remove_layer_aovs(layer3d, remove)
print("Something removed?", something_removed)


Cheers,

Edit: fixed script
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 421
Joined: Wed Jan 13, 2016 10:10 am

Re: How to remove AOV for image

Unread postby stepanyantg » Thu Sep 30, 2021 10:50 pm

Hi Anthony,

I tested the script , and it keeps the AOVs in remove list and removes rest AOVs.

Thanks,
Tigran
stepanyantg
 
Posts: 2
Joined: Wed May 15, 2019 3:48 pm

Re: How to remove AOV for image

Unread postby anemoff » Fri Oct 01, 2021 9:31 am

My bad, there was a mistake in the script. I updated it in my previous post.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 421
Joined: Wed Jan 13, 2016 10:10 am


Return to Scripting