Delanimation

Delano Athias - Animator

Restoring Default Values on Selected Items with Python in Maya

In this lesson, we will build a simple Python tool in Maya to reset any select control and custom channel back to its default value. Level: Beginner to Intermediate

#Import Maya's Command Module
import maya.cmds as mc
#Store selected transforms in variable "sel"
sel = mc.ls(sl=True, type='transform')
#Return selection
print sel
#For Loop - iterative through variable "sel" with "each", and do the following...
for each in sel:
    #Store keyable, unlocked channels in variable "keyable"
    keyable = mc.listAttr(each, k=True, u=True)
    print keyable
    #For Loop - iterative through all keyable/unlocked channels
    for key in keyable:
        #Get default values of each keyable/unlocked channel
        defaults = mc.attributeQuery(key, n=each, ld=True)
        #For Loop - set each item back to its default value
        for dv in defaults:
            print dv
            mc.setAttr(each + '.' + key, dv)