Animation Handle Creator

From Emily Carr University Wiki
Jump to: navigation, search

This is a a .MEL script used to create a series of nested NURBS circles, each colored and labeled for easy animating.

int $i;
while (objExists("CONSTRAIN_ME_"+$i))
{
$i++;
}
string $control1 = ("CONSTRAIN_ME_"+$i);
string $control2 = ("ANIMATE_ME_"+$i);
string $control3 = ("ANIMATE_ME_MORE_"+$i);
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1; objectMoveCommand;
rename "nurbsCircle1" $control1;
rename ("CONSTRAIN_ME_Shape"+$i) ("CONSTRAIN_ME_"+$i+"Shape");
setAttr ($control1+".scaleZ") 10;
setAttr ($control1+".scaleX") 10;
setAttr ($control1+".scaleY") 10;
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1; objectMoveCommand;
rename "nurbsCircle1" $control2;
rename ("ANIMATE_ME_Shape"+$i) ("ANIMATE_ME_"+$i+"Shape");
setAttr ($control2+".scaleZ") 8;
setAttr ($control2+".scaleX") 8;
setAttr ($control2+".scaleY") 8;
select -r $control2 $control1 ;
parent;
select -cl ;
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1; objectMoveCommand;
rename "nurbsCircle1" $control3;
rename ("ANIMATE_ME_MORE_Shape"+$i) ("ANIMATE_ME_MORE_"+$i+"Shape");
setAttr ($control3+".scaleZ") 7;
setAttr ($control3+".scaleX") 7;
setAttr ($control3+".scaleY") 7;
select -cl ;
select -r $control3 ;
select -tgl $control2 ;
parent;
setAttr ($control2+"Shape.overrideEnabled") 1;
setAttr ($control2+"Shape.overrideColor") 9;
setAttr ($control3+"Shape.overrideEnabled") 1;
setAttr ($control3+"Shape.overrideColor") 20;
setAttr ($control1+"Shape.overrideEnabled") 1;
setAttr ($control1+"Shape.overrideColor") 13;
select -cl ;
select -r $control1 ;
group; xform -os -piv 0 0 0;
rename "group1" ("CONSTRAIN_NULL_GRP"+$i);
$i++;


Here's a quick code breakdown to show what this MEL does:


//declares a new variable, set its type to "integer"
int $i;
// The while loop runs a command only when the test condition holds true
// A while loop mainly consists of:
// while (test condition;) {operation;}
// objExists returns t/f based on whether or not an object exists
//if CONTRAIN_ME_# exists... add 1 to $i
while (objExists("CONSTRAIN_ME_"+$i))
{
$i++;
}
//declares three new varibles "control1, control2, and control3"
string $control1 = ("CONSTRAIN_ME_"+$i);
string $control2 = ("ANIMATE_ME_"+$i);
string $control3 = ("ANIMATE_ME_MORE_"+$i);
//create a circle with these parameters. >>Look up "circle" in maya help to get a breakdown of each parameter
//object Move Command, moves any object to the center
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1; objectMoveCommand;
//rename the newly created circle to "CONTRAIN_ME_"
rename "nurbsCircle1" $control1;
//rename the circle's shape node to "CONTRAIN_ME_1_Shape" instead of "CONTRAIN_ME_Shape_1"
rename ("CONSTRAIN_ME_Shape"+$i) ("CONSTRAIN_ME_"+$i+"Shape");
// Result: control1 //a scale the circle uniformly in all directions to "10"
setAttr ($control1+".scaleZ") 10;
setAttr ($control1+".scaleX") 10;
setAttr ($control1+".scaleY") 10;
// Result: CONSTRAIN_ME1 //
//create another circle, center it
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1; objectMoveCommand;
//rename that circle to "ANIMATE_ME"
rename "nurbsCircle1" $control2;
//rename that circle's shape node
rename ("ANIMATE_ME_Shape"+$i) ("ANIMATE_ME_"+$i+"Shape");
// Result: control1 // scale the circle to "8"
setAttr ($control2+".scaleZ") 8;
setAttr ($control2+".scaleX") 8;
setAttr ($control2+".scaleY") 8;
// Result: ANIMATE_ME //
//select -r $control2 ; Select "ANIMATE ME, then select CONTRAIN_ME"
select -r $control2 $control1 ;
//parent those two together
parent;
//clear selection
select -cl ;
//create another circle, center it
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1; objectMoveCommand;
//rename that circle to "ANIMATE_ME_MORE"
rename "nurbsCircle1" $control3;
//rename the shapenode
rename ("ANIMATE_ME_MORE_Shape"+$i) ("ANIMATE_ME_MORE_"+$i+"Shape");
//scale this circle to "7"
setAttr ($control3+".scaleZ") 7;
setAttr ($control3+".scaleX") 7;
setAttr ($control3+".scaleY") 7;
//Clear the selection
select -cl ;
//select replace "ANIMATE_ME_MORE"
select -r $control3 ;
//select toggle "ANIMATE_ME"
select -tgl $control2 ;
//parent those two
parent;
//set each circle to allow display overrides, and change the color
setAttr ($control2+"Shape.overrideEnabled") 1;
setAttr ($control2+"Shape.overrideColor") 9;
setAttr ($control3+"Shape.overrideEnabled") 1;
setAttr ($control3+"Shape.overrideColor") 20;
setAttr ($control1+"Shape.overrideEnabled") 1;
setAttr ($control1+"Shape.overrideColor") 13;
//clear your selection
select -cl ;
//select "CONTRAIN_ME" which is at the base of the hierarchy
select -r $control1 ;
//group that object, then in object space (-os) center the pivot (-piv 0, 0, 0)
group; xform -os -piv 0 0 0;
//rename the group created at the end,
rename "group1" ("CONSTRAIN_NULL_GRP"+$i);
//Add one to the integer counter
$i++;