Animation Transfer MEL Script

Standard

This is the MEL script for my animation transfer.  The script allows one animated object (the source) to be transferred to another unanimated object (the target). The script is simple as it only works with simple objects within Maya. You must select the animated object first then select the “Select Animation Source” button. Next, Select the unanimated object and select the “Select Animation Target” button. Finally, hit the “Copy Keys” button. This will transfer the animated keys from the source to the target. 

/*Author: Mark Tomczyk
Title: Animation Transfer
Description: This mel script transfers animation keyframes from one animated object to an unanimated object. The GUI window allows the user to select the source’s keyed channels and transfer the animation keyframes to the target.
*/

//Create a proc for the source
proc aTSelectSource()
{
//Create a global string that recognises the source
global string $mTomczyksource[];
//Create a string that selects the source
string $mTomczyksource[] = `ls -sl`;
}

//Create a proc for the target
proc aTSelectTarget()
{
//Create a global string that recognises the target
global string $mTomczyktarget[];
//Create a string that selects the target
string $mTomczyktarget[] = `ls -sl`;
}

//Create a proc to store the source and target to copy the keys
proc aTCopyKeys()
{
//Place the global strings within the proc so that they are recognised
global string $mTomczyksource[];
global string $mTomczyktarget[];

//Create a string that recognises object’s channels that have been keyed
string $channels[] = `listAttr -keyable $mTomczyksource[0]`;

//This tells the target object to look for the channels of the source object
for ($channel=0; $channel < size($channels); $channel++)

{
//Create a string that lists the channels that have been keyed in the source
string $outpNode[] = `listConnections -d true ($mTomczyksource[0] + “.” + $channels[$channel])`;

//Create an if statement that will ignore and pass through any channels that are not keyed in the source
if ($outpNode[0] != “”)
{
//Create an if statement that will copy any keyed channels that are found in the soucre and paste them to the target
if (`objectType $outpNode[0]` == “animCurveTL”)

copyKey -attribute $channels[$channel] -option curve $mTomczyksource[0];
pasteKey -attribute $channels[$channel] -option replaceCompletely $mTomczyktarget[0];
}
}
}

 

//Window Selection
if (`window -exists aTwin`) //Test if a window exists with teh ELF name aTwin
deleteUI -window aTwin; //If test is true delete the window with the ELF name aTwin

//Create a window with the title “Animation Transfer by M.Tomczyk”
window -title “Animation Transfer by M.Tomczyk”
//Create a minimize button
-minimizeButton true
//Create a maximize button
-maximizeButton true
//The window cannot be resized
-sizeable true
aTwin;

//This is a column layout with the ELF name clmLyt1
columnLayout
clmLyt1;
//This is a frame layout with a width of 500 pixals
frameLayout -width 500
//Create a label called “Select Source”
-label “Select Source”
//ELF name for the first frame layout
frmLyt1;

//Create a string with a button lebelled “Select Animation Source” with a command that performs the proc “aTSelectSource”
string $selBttn1 = `button -label “Select Animation Source” -command aTSelectSource`;

//Create a second frame layout with a width of 500 pixals
frameLayout -width 500
//Create a label called “Select Target”
-label “Select Target”
//ELF name for the second frame layout
frmLyt2;
//Create a string with a button lebelled “Select Animation Target” with a command that performs the proc “aTSelectTarget”
string $selBttn2 = `button -label “Select Animation Target” -command aTSelectTarget`;

//Create a third frame layout with a width of 500 pixals
frameLayout -width 500
//Create a label called “Copy Animation”
-label “Copy Animation”
//ELF name for the third frame layout
frmLyt3;
//Create a string with a button lebelled “Copy Keys” with a command that performs the proc “aTCopyKeys”
string $CopyBttn1 = `button -label “Copy Keys” -command aTCopyKeys`;
//Shows window
showWindow aTwin;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s