Hi ,
Could you please give an example how to remove an existing AOV from image?
Thanks,
Tigran
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)