Skip to content

Instantly share code, notes, and snippets.

Created January 20, 2017 19:35
Show Gist options
  • Save anonymous/9ba64a675b52d2475c0386b532d425e9 to your computer and use it in GitHub Desktop.
Save anonymous/9ba64a675b52d2475c0386b532d425e9 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
# This will replace the values in all selected objects (based on order of selection) to "<new_name>_<index in selection>"
# Feel free to replace all these variables to whatever specifics you need.
shader_type = 'aiSurface'
use_selection = True
attribute = 'aovid'
new_name = 'assetID'
padding = 2
for index, shader in enumerate(pm.ls(type=shader_type, sl=use_selection)):
shader.attr(attribute).set('%s_%{PAD}d'.format(PAD='0' + padding) % (prefix, index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment