Friday, February 4, 2011

joint Zero-ing

Here's a simple Python script that is used to zero-out selected joints' or given joint's rotation value and joint orient value. 

INSTRUCTION:
For the first argument, 'jointName' is used to specify a given joint name. If you intend to run the script for selected joints instead, give a 'None' or do not use this argument at all. It is defaulted as 'None' though. Second and third argument is 'rot' and 'jo'. Give it a 1 to 'rot' to zero-out rotation values or a 1 to 'jo' to zero-out joint orient values. Otherwise, give them a 0 to do nothing on that particular arguments.

EXAMPLE:
1) This will zero-out rotation values for joint1, but its joint orient will not be affected:
 
jointZero (jointName='joint1', rot=1, jo=0)

2) This will zero-out rotation values and joint orient values for all selected joints:

jointZero (rot=1,jo=1)

FULL SCRIPTS (to run before hand):


def jointZero (jointName=None, rot=1, jo=1):

    if jointName == None:
    
        sel = cmds.ls(sl=True)
        for joint in sel:
            if rot == 1:
                cmds.setAttr ('%s.rx'%joint, 0)
                cmds.setAttr ('%s.ry'%joint, 0)
                cmds.setAttr ('%s.rz'%joint, 0)    
                
            if jo == 1:
                cmds.setAttr ('%s.jointOrientX'%joint, 0)
                cmds.setAttr ('%s.jointOrientY'%joint, 0)
                cmds.setAttr ('%s.jointOrientZ'%joint, 0)                    
        
    else:
        
        if rot == 1:
            cmds.setAttr ('%s.rx'%jointName, 0)
            cmds.setAttr ('%s.ry'%jointName, 0)
            cmds.setAttr ('%s.rz'%jointName, 0)    
            
        if jo == 1:
            cmds.setAttr ('%s.jointOrientX'%jointName, 0)
            cmds.setAttr ('%s.jointOrientY'%jointName, 0)
            cmds.setAttr ('%s.jointOrientZ'%jointName, 0) 



Note that this is a very simple script. Fail-proof procedures are not added. So make sure your selection type is 'joint' and no rotation or joint orient attributes are locked or non-keyable. 


That is all for now. Hope this sheds some lights to the blog's viewers.

No comments:

Post a Comment