Page 1 of 1

How to remove AOV for image

Unread postPosted: Thu Sep 30, 2021 3:06 am
by stepanyantg
Hi ,
Could you please give an example how to remove an existing AOV from image?


Re: How to remove AOV for image

Unread postPosted: Thu Sep 30, 2021 10:29 am
by anemoff

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`.

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_enabled_attr = layer3d.get_attribute('enabled_aov_list')
current_enabled = ix.api.BoolArray()

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

# 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_enabled.add("{}".format(int(current_enabled[i]))) # convert boolean to 0 or 1

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)

return True

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


Edit: fixed script

Re: How to remove AOV for image

Unread postPosted: Thu Sep 30, 2021 10:50 pm
by stepanyantg
Hi Anthony,

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


Re: How to remove AOV for image

Unread postPosted: Fri Oct 01, 2021 9:31 am
by anemoff
My bad, there was a mistake in the script. I updated it in my previous post.