Tuesday, January 11, 2011

Animation Transfer Script

A friend of mine was asking me if it is possible to have a script that can save the animation data into a text file and load the saved animation data text file into another object. So I wrote a simple Python script that could perform such operation. It saves the keys as well as its animation curves and tangents.

The GUI is pretty simple to navigate. There are two tabs, LOAD and SAVE. To save out animation data into a text file, first select the object with the animation that you like to save out. Then click 'Browse' to browse to a directory where you want to save the text file containing the animation data. You can specify the start frame and end frame, as well as choosing the channels you like to save such as translate, rotate, scale and visibility. I made an additional custom attribute if you ever need one. The 'Save Data' button executes the saving data script. And to load the animation data, all you need to do is to choose your object, click 'Browse' to select your saved animation data text file, and decide whether if you like to remove the current keys on the selected object by ticking the checkbox. A click on 'Load Data' will executes the loading data script.

That is all.

Download link: Python File : jwAnimTransfer.py

** Note that this script is very simple. It can only save 1 object's animation at one time. Not that great, I know! Well, if you have any suggestions to make it more useful, let me know. Thanks!

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 ==
            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)