3D animation,rigging,coding, math ,fun stuff welcome !

dof_toggle.py

"""
Copyright (C) 2009 Rick Fronek
melvin.3d@gmail.com

Python Script File:
Function List:
                    dof_toggle()
                   
MODIFY THIS AT YOUR OWN RISK

Update Date:    Feb 07 2010

Description: Sometimes I get a skeleton from a client and all or some
                       joints degrees of freedom are locked. This scripts goes through
                       and makes sure that selected joints have DOF checked ON/OFF.
Install :
                Put it into your maya script dir and then
                rehash or restart maya. Use regular import.

                from utils import dof_toggle

"""

import maya.cmds as mc

def dof_toggle(value):
    """
    Simple function that grabs all the joints in the scene
    and toggle Degrees of Freedom ON/OFF.
    value == 0 >>> turn off the dof
    value == 1 >>> turn on the dof

    """
    #================
    # get all joints
    lJoints = mc.ls(type='joint')
    print "Total joint found in the scene is %i" % (len(lJoints))
    # simple loop
    for joint in lJoints:
        lX = mc.getAttr(joint + '.jointTypeX')
        lY = mc.getAttr(joint + '.jointTypeY')
        lZ = mc.getAttr(joint + '.jointTypeZ')

        # if locked/unchecked - X axis
        if lX == 0 and value == 0:
            mc.setAttr(joint + '.jointTypeX',1)
            mc.setAttr(joint + '.rx',lock=False)
        # if unlocked/checked
        elif lX == 1 and value == 1:
            mc.setAttr(joint + '.jointTypeX',0)
            mc.setAttr(joint + '.rx',lock=True)

        # if locked/unchecked - X axis
        if lY == 0 and value == 0:
            mc.setAttr(joint + '.jointTypeY',1)
            mc.setAttr(joint + '.ry',lock=False)
        # if unlocked/checked
        elif lY == 1 and value == 1:
            mc.setAttr(joint + '.jointTypeY',0)
            mc.setAttr(joint + '.ry',lock=True)

        # if locked/unchecked - X axis
        if lZ == 0 and value == 0:
            mc.setAttr(joint + '.jointTypeZ',1)
            mc.setAttr(joint + '.rz',lock=False)
        # if unlocked/checked
        elif lY == 1 and value == 1:
            mc.setAttr(joint + '.jointTypeZ',0)
            mc.setAttr(joint + '.rz',lock=True)


        # confirm node in the scene
        print joint,

    mc.refresh()
#================