Skip to content

Instantly share code, notes, and snippets.

@AndresMWeber
Forked from anonymous/set_shader_attribute.py
Last active January 20, 2017 21:30
Show Gist options
  • Save AndresMWeber/f6109abc475e5a053640632648fe2c36 to your computer and use it in GitHub Desktop.
Save AndresMWeber/f6109abc475e5a053640632648fe2c36 to your computer and use it in GitHub Desktop.
Set all shader attributes to a new prefixed and indexed string
import pymel.core as pm
def set_all_aovIds(value, targets=None, object_type='alSurface', padding=2, attr_basename='aovId', number_of_indexes=8, use_selection=True):
if not targets:
targets = pm.ls(type=object_type, sl=use_selection)
for target in targets:
for index in range(1, number_of_indexes+1):
try:
new_value = '%s_%{PAD}d'.format(PAD='0' + str(padding)) % (value, index)
target.attr(attr_basename+str(index)).set(new_value, type="string")
except pm.MayaAttributeError:
print('Attribute %s did not exist.' % attr_basename+str(index))
# changing padding
# set_attributes_in_order("test", padding=4)
# changing shader we're looking for
# set_attributes_in_order("test", object_type='aiSurface')
# changing to set less aovIds
# set_attributes_in_order("test", number_of_indexes=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment