//James Parks 09-03-03 //www.arcsecond.net //jpTransferAnim_v1.5.mel //***Now 20% more useful!!!*** //I created this script to preserve animation channels on //custom character controls while I was making adjustments //to the character rigging. //******** To Use: ******** //Select your animated source object and then your target object. //Use the "Copy Attr" button to copy user-defined attributes. //Use the "Transfer" button to copy animation curves from the //source object to the target object. //When Transferring, use the radio buttons to transfer either //the entire animation curve or just the current values. //If the source object is not animated only the values will be //tranfered. //Known Limitations: //1.) only one control/storage object duo at a time //2.) doesn't handle enumerated attributes, only numeric //3.) very little error checking - wheeeee, ain't it fun?! //update history //v1.5 // added the attribute array to only copy checked channels // added some user notification of when events happen //v1.4 // added the ability to either copy the entire animation curve // or just to copy the current values. And optimized the code. //v1.3 // oops, I screwed up and it was copying curves twice //v1.2 // fixed a problem regarding locked channels // thanks to Erick Miller for providing the clue // even though he doesn't know he did //v1.1 // added GUI and some error checking global proc jpCopyAttr() { string $animObj[] = `ls -sl`; if (`size($animObj)` <= 0) error "No objects selected"; //list all user-defined attributes and recreate them on the new object string $udAttr[] = `listAttr -ud $animObj[0]`; print "\nUser-Defined Attributes Copied:\n"; for ($attr in $udAttr) { if (!`attributeExists $attr $animObj[1]`) { //select $animObj[0]; float $hasRange = `attributeQuery -n $animObj[0] -re $attr`; float $default[] = `attributeQuery -n $animObj[0] -ld $attr`; string $type = `getAttr -typ ($animObj[0] + "." + $attr)`; select $animObj[1]; if($hasRange != 0) { float $range[] = `attributeQuery -n $animObj[0] -r $attr`; addAttr -ln $attr -at $type -min $range[0] -max $range[1] -dv $default[0]; } else { addAttr -ln $attr -at $type -dv $default[0]; } setAttr -e -keyable true ($animObj[1] + "." + $attr); } print ("-----" + $attr + "\n"); }//end for select $animObj; print "Finished Copying User-Defined Attributes"; }//end proc global proc jpTransAnim() { string $animObj[] = `ls -sl`; if (`size($animObj)` <= 0) error "No objects selected"; string $allAttr[] = `listAttr -k $animObj[0]`; string $udAttr[] = `listAttr -ud $animObj[0]`; int $transX = `checkBoxGrp -q -v1 "transAxes"`; int $transY = `checkBoxGrp -q -v2 "transAxes"`; int $transZ = `checkBoxGrp -q -v3 "transAxes"`; int $rotX = `checkBoxGrp -q -v1 "rotAxes"`; int $rotY = `checkBoxGrp -q -v2 "rotAxes"`; int $rotZ = `checkBoxGrp -q -v3 "rotAxes"`; int $scaleX = `checkBoxGrp -q -v1 "scaleAxes"`; int $scaleY = `checkBoxGrp -q -v2 "scaleAxes"`; int $scaleZ = `checkBoxGrp -q -v3 "scaleAxes"`; int $visAttr = `checkBoxGrp -q -v1 "visAttr"`; int $udAttrs = `checkBoxGrp -q -v1 "udAttrs"`; print "\nTransfering Animation Curves for:\n"; for ($atr in $allAttr) { float $isKeyed = `copyKey -time ":" -cb anim -at $atr $animObj[0]`; int $isAttrUd = 0; for($attr in $udAttr) { if($atr == $attr) $isAttrUd = 1; } //Checks Copy Type whether to copy animCurves or just current values //and then does so based on which check boxes are checked if (`radioButtonGrp -q -sl "copyType"` != 1) { float $val = `getAttr ($animObj[0] + "." + $atr)`; //catch(`setAttr ($animObj[1] + "." + $atr) $val`); if ($atr == "translateX" && $transX == 1) catch(`setAttr ($animObj[1] + "." + $atr) $val`); if ($atr == "translateY" && $transY == 1) catch(`setAttr ($animObj[1] + "." + $atr) $val`); if ($atr == "translateZ" && $transZ == 1) catch(`setAttr ($animObj[1] + "." + $atr) $val`); if ($atr == "rotateX" && $rotY == 1) catch(`setAttr ($animObj[1] + "." + $atr) $val`); if ($atr == "rotateY" && $rotY == 1) catch(`setAttr ($animObj[1] + "." + $atr) $val`); if ($atr == "rotateZ" && $rotY == 1) catch(`setAttr ($animObj[1] + "." + $atr) $val`); if ($atr == "scaleX" && $scaleX == 1) catch(`setAttr ($animObj[1] + "." + $atr) $val`); if ($atr == "scaleY" && $scaleY == 1) catch(`setAttr ($animObj[1] + "." + $atr) $val`); if ($atr == "scaleZ" && $scaleZ == 1) catch(`setAttr ($animObj[1] + "." + $atr) $val`); if ($atr == "visibility" && $visAttr == 1) catch(`setAttr ($animObj[1] + "." + $atr) $val`); else if ($udAttrs == 1 && $isAttrUd == 1) catch(`setAttr ($animObj[1] + "." + $atr) $val`); } else if ($isKeyed != 0) { if ($atr == "translateX" && $transX == 1) catch(`pasteKey -cb anim -option insert ($animObj[1] + "." + $atr)`); if ($atr == "translateY" && $transY == 1) catch(`pasteKey -cb anim -option insert ($animObj[1] + "." + $atr)`); if ($atr == "translateZ" && $transZ == 1) catch(`pasteKey -cb anim -option insert ($animObj[1] + "." + $atr)`); if ($atr == "rotateX" && $rotX == 1) catch(`pasteKey -cb anim -option insert ($animObj[1] + "." + $atr)`); if ($atr == "rotateY" && $rotY == 1) catch(`pasteKey -cb anim -option insert ($animObj[1] + "." + $atr)`); if ($atr == "rotateZ" && $rotZ == 1) catch(`pasteKey -cb anim -option insert ($animObj[1] + "." + $atr)`); if ($atr == "scaleX" && $scaleX == 1) catch(`pasteKey -cb anim -option insert ($animObj[1] + "." + $atr)`); if ($atr == "scaleY" && $scaleY == 1) catch(`pasteKey -cb anim -option insert ($animObj[1] + "." + $atr)`); if ($atr == "scaleZ" && $scaleZ == 1) catch(`pasteKey -cb anim -option insert ($animObj[1] + "." + $atr)`); if ($atr == "visibility" && $visAttr == 1) catch(`pasteKey -cb anim -option insert ($animObj[1] + "." + $atr)`); else if ($udAttrs == 1 && $isAttrUd == 1) catch(`pasteKey -cb anim -option insert ($animObj[1] + "." + $atr)`); } else { warning "An Error has Occured in deciding the Copy Type"; //float $val = `getAttr ($animObj[0] + "." + $atr)`; //catch(`setAttr ($animObj[1] + "." + $atr) $val`); } print ("-----" + $atr + "\n"); }//end for print "\nFinished Transfer"; }//end proc global proc jpBatchTrans() { string $selected[] = `ls -sl`; print $selected; int $size = `size($selected)`; int $remainder = $size % 2; if($remainder != 0) error "This works in pairs, select an even number"; print $size; if ($size <= 0) error "No objects selected"; for($i=0; $i<$size; $i+=2) { select -clear; print $selected[$i]; print $selected[$i+1]; select $selected[$i]; select -add $selected[$i+1]; jpTransAnim(); }//end for }//end proc global proc jpTransferAnim() { string $winName = "jpTransferAnim"; if (`window -exists $winName`) deleteUI $winName; window -t "Transfer Animation" -wh 200 70 -rtf 1 $winName; rowColumnLayout -nr 3 -rh 1 50 -rh 2 15 -rh 3 90 ; rowColumnLayout -nc 2 -cw 1 100 -cw 2 100 ; button -w 100 -l "Copy User Attr's" -c "jpCopyAttr()"; button -w 100 -l "Transfer" -c "jpTransAnim()"; button -w 100 -l "Batch" -c "jpBatchTrans()"; setParent .. ; radioButtonGrp -w 200 -h 15 -nrb 2 -cw 1 100 -cw 2 100 -l1 "Whole Curves" -l2 "Current Values" -sl 1 "copyType" ; setParent ..; rowColumnLayout -nr 6 -rh 1 15 -rh 2 15 -rh 3 15 -rh 4 15 -rh 5 15 -rh 6 15 ; text -fn "boldLabelFont" -al "center" "Attributes To Transfer"; checkBoxGrp -w 200 -h 15 -ncb 3 -label "Transform" -cal 1 "left" -l1 "X" -l2 "Y" -l3 "Z" -v1 1 -v2 1 -v3 1 -cw 1 100 -cw 2 33 -cw 3 33 -cw 4 33 "transAxes" ; checkBoxGrp -w 200 -h 15 -ncb 3 -label "Rotate" -cal 1 "left" -l1 "X" -l2 "Y" -l3 "Z" -v1 1 -v2 1 -v3 1 -cw 1 100 -cw 2 33 -cw 3 33 -cw 4 33 "rotAxes" ; checkBoxGrp -w 200 -h 15 -ncb 3 -label "Scale" -cal 1 "left" -l1 "X" -l2 "Y" -l3 "Z" -v1 1 -v2 1 -v3 1 -cw 1 100 -cw 2 33 -cw 3 33 -cw 4 33 "scaleAxes" ; checkBoxGrp -w 200 -h 15 -ncb 1 -label "Visibility" -v1 1 -cal 1 "left" -cw 1 100 -cw 2 100 "visAttr" ; checkBoxGrp -w 200 -h 15 -ncb 1 -label "User Defined" -v1 1 -cal 1 "left" -cw 1 100 -cw 2 100 "udAttrs" ; showWindow $winName; } jpTransferAnim;