Skip to content

Instantly share code, notes, and snippets.

@patwooky
Created October 1, 2017 10:02
Show Gist options
  • Save patwooky/d30a6254a548196ce12da4ac194692ec to your computer and use it in GitHub Desktop.
Save patwooky/d30a6254a548196ce12da4ac194692ec to your computer and use it in GitHub Desktop.
Maya script. For each of the selected transform nodes, create a int type attr to the shape node, and set a running value to each.
import pymel.core as pm
# select the transform for all your objects before running this script
objList = pm.ls(sl=True) # list of selected objects (transform nodes)
objShapesList = []
attrName = 'myAttrName' # this is the name of the attribute
for obj in objList:
# loops through all selection
try:
objShape = obj.getShape()
objShapesList.append(objShape)
except:
print ('{} has no shape nodes. skipping.'.format(obj))
continue
pm.addAttr(objShape, ln=attrName, at='float', writable=True, keyable=True)
print ('attr "{}" added to {}'.format(attrName, objShape))
# sets a running integer value to each object shape in the list
# ie.
# shape1.myAttrName -> 0
# shape2.myAttrName -> 1
# ...
# shape10.myAttrName -> 9
for shapeId in range(len(objShapesList)):
objShapesList[shapeId].attr(attrName).set(shapeId)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment