Tuesday, January 4, 2011

Joint Labeling

I developed this script about a year ago. It is used to rename the joint labeling and set the 'side' of the selected joints according to their prefix. In my case, I used 'cc' for center, 'll' for left side and 'rr' for right side. You may modify that to suit your preference. It is important to make sure the name on both sides of the selected joints are the same except its prefix. The script is as below:


# Import Maya functions

import maya.cmds as cmds

# Prefixes change here

leftSide = 'll'
rightSide = 'rr'
center = 'cc'

def jointLabeling ():

    sel = []
    sel = cmds.ls (sl=True, fl=True)

    for i in sel:

        afterName=i.split ('_', 1)[0] # take the starting prefix and check
        afterNameTwo=i.split ('_', 1)[1] # take the obj's name and check

        if afterName ==
leftSide:
            cmds.setAttr ('%s.side'%i, 1)
            cmds.setAttr ('%s.type'%i, 18)
            cmds.setAttr ('%s.otherType'%i, '%s'%afterNameTwo, type= "string")
            print 'Labeled %s prefix called %s' %(afterName, afterNameTwo)

        if afterName == rightSide:
            cmds.setAttr ('%s.side'%i, 2)
            cmds.setAttr ('%s.type'%i, 18)
            cmds.setAttr ('%s.otherType'%i, '%s'%afterNameTwo, type= "string")
            print 'Labeled %s prefix called %s' %(afterName, afterNameTwo)

        if afterName == center:
            cmds.setAttr ('%s.side'%i, 0)
            cmds.setAttr ('%s.type'%i, 18)
            cmds.setAttr ('%s.otherType'%i, '%s'%afterNameTwo, type= "string")
            print 'Labeled %s prefix called %s' %(afterName, afterNameTwo)



No comments:

Post a Comment