Useful Maths
∏=circumference/diameter
∏=3.141592
Circumference of a
Circle = 2∏* radius
sin(angle)=O/H
cos(angle)=A/H
tan(angle)=O/A
degrees=radians*(180/∏)
radian=degrees*(∏/180)
|
0° |
90° |
180° |
270° |
360° |
|
sin(0°)=0 |
sin(90°)=1 |
sin(180°)=0 |
sin(270°)=-1 |
sin(360°)=0 |
|
cos(0°)=1 |
cos(90°)=0 |
cos(180°)=-1 |
cos(270°)=0 |
cos(360°)=1 |
√H=A²+O²
x2-x1=length of a line
Calculating the length of
an arbitrary line
length=
What are Radians?
One radian is the angle of the arc created by wrapping the
radius around the circumference.
degrees=radians*(180/∏)
radian=degrees*(∏/180)
x²= x¹*cos(angle)-y¹*sin(angle);
y²= x¹*sin(angle)+y¹*cos(angle);
Selecting
//-selection (-sl):lists
objects that are currently selected.
ls -sl;
//-cameras (-ca): Lists camera shapes.
ls -cameras;
//-lights (-lt):lists all lights
ls -lights;
//-materials (-mat): lists all materials
ls -materials;
Properties
Query -q -radius
Edit -e radius 5
Create is default so not specified
eg.
// Get the current frame on the timeline
currentTime -q;
// Set the current postion on the timeline to frame 20
currentTime -e 20;
Create Your 1st Window
window -title "My First Window : Sphere" mySphWindow;
columnLayout mainCol;
button -label "Create Sphere" -command "polySphere"
spherebutton;
showWindow mySphWindow; |
Create Your 2nd Window
note : escape character \n (new line) \t (tab) \"(quotation)
\\ (slash) \r (return)
eg.
print "Ï want to play \\ \" \r on \r a \\ \n new line";
if(`window -exists mySphWindow`)
{
deleteUI mySphWindow;
}
window -title "My 2nd Window" mySphWindow;
columnLayout -adjustableColumn 1 mainCol;
polySphere;
button -label "Print Hello Mum" -command "print(\"Hello
Mum\")" hellobutton;
attrFieldSliderGrp -attribute "polySphere1.radius"
radiusSlider;
showWindow mySphWindow; |
Array
// create 5 PolyShere in your
scene and select them
string $selObjs[]=`ls –sl`;
print(`size $selObjs`); // number of elements in an array |
Vector
vector $position=<<1.23,6.54,7.89>>;
print("[ X : "+ $position.x + " ][ Y : "+ $position.y + " ][
Z : "+ $position.z + "]"); |
sphrand (Sphere Random)
eg.
sphrand(10); //returns a
random x, y, z value within a sphere of radius 10
| for($x=0;$x<50;$x++) {
vector $randomPos=sphrand(20);
nurbsCube -pivot ($randomPos.x) ($randomPos.y) ($randomPos.z);
}
|

If : Conditional
Statements
eg.
if(a<b)
{
do something;
}
a < b [a is less than b]
a > b [a is greater than b]
a == b [a is equal to b]
! b [not b]
a != b [a is not equal to b]
a >= b [a is greater than or equal to b]
a <= b [a is less than or equal to b]
eg.
int $x=3;
if ($x>5)
{
print("x is greater than 5");
}
else
{
print("x is less than 5");
} |
eg.
float $scaleZ=`getAttr pSphere1.scaleZ`;
if($scaleZ > 2)
{
setAttr "lambert1.color" 1 0 0;
}
else
{
setAttr "lambert1.color" 0 0 1;
} |
If else : Conditional
Statements
//---------------------------------------------------------
//
// example 01 : Switch (toggle) the Resolution Gate ON or OFF
//
//---------------------------------------------------------
// Query the
name of the Camera used in the current Panel
$whichPanel = `getPanel -withFocus`;
string $nameCam=`modelPanel -q -camera
($whichPanel)`;
// Query the displayResolution status of the
camera
if(`camera -q -displayResolution $nameCam` == 1)
{
//turn it off
camera -e -displayResolution off $nameCam;
camera -e -overscan 1 $nameCam;
}
else
{
// turn it on
camera -e -displayResolution on $nameCam;
camera -e -overscan 1.5 $nameCam;
} |

Note : Overscan
value changes the amount of space surrounding the view
guides, making them easier to see. The default value is 1.
To change the value of the OverScan
View >
Select Camera > DisplayOptions > Overscan > 1.5
While Loops
//--------------------------------------------------
//
// example 01 : Create a Staircase (While loop)
//
//--------------------------------------------------
int $x=0;
while ($x<20)
{
$x=$x+1;
polyCube -name ("newStep" + $x) -width 10 -depth 4;
move -relative 0 (20-$x) (2*$x);
} |
While versus For Loops :
Alternative Method
//--------------------------------------------------
//
// example 01 : Create a Staircase (For loop)
//
//--------------------------------------------------
for($x=0;$x<20;$x=$x+1)
{
polyCube -name ("newStep" + $x) -width 10 -depth 4
-height 1;
move -relative 0 (20-$x) (2*$x);
} |

For Loops
//--------------------------------------------------
//
// example 01 : Create a spiral of NURBS spheres
//
//--------------------------------------------------
for($x=0;$x<20;$x++)
{
float $sin=sin($x);
float $cos=cos($x);
sphere -pivot $sin $x $cos;
} |

//--------------------------------------------------
//
// example 02 : Create a spiral of circle splines and
// and loft them.
//
//--------------------------------------------------
circle;
move 4 0 0;
move 0 0 0 nurbsCircle1.rotatePivot;
for($x=0;$x<20;$x++)
{
duplicate;
rotate -r 0 30 0;
move -r 0 0.7 0;
}
select -all;
loft -sectionSpans 3; |

//--------------------------------------------------
//
// example 03 : Create a spiral staircase and a pillar
// through the middle.
//
//--------------------------------------------------
float $numSteps=50;
float $stepHeight=1;
float $stepGap=0.5;
for($x=0;$x<($numSteps);$x++)
{
polyCube -width 10 -height ($stepHeight) -depth 4;
move -relative 10 ($x*($stepHeight+$stepGap)) 0;
xform -pivots -10 0 0;
rotate -relative 0 ($x*15) 0;
}
polyCylinder -radius 5.2 -height (($stepHeight+$stepGap)*$numSteps);
move -r 0 ((`getAttr polyCylinder1.height`)/2) 0;
|

Nested For Loop
//--------------------------------------------------
//
// example 01 : Create a grid of Cubes
//
//--------------------------------------------------
for($rows=0;$rows<20;$rows++)
{
for ($cols=0;$cols<20;$cols++)
{
float $yscale=rand(1,10);
polyCube;
move -r ($cols*-2) 0.5 ($rows*2);
xform -pivots 0 -0.5 0;
scale -r 1 $yscale 1;
}
} |

Procedure : Create a Big
Cube
//--------------------------------------------------
//
// example 01 : Create a big cube with defined values
//
//--------------------------------------------------
proc bigCube()
{
polyCube -name "myCube"
-width 10
-height 8
-depth 6
-subdivisionsWidth 3
-subdivisionsHeight 3
-subdivisionsDepth 3;
move -r 0 15 0;
}
bigCube; |

Procedure : Create any
Cube
//---------------------------------------------------------
//
// example 02 : Create a cube, any size, position and
rotation
//
//---------------------------------------------------------
proc bigCube( string $cubeName,
float $cWidth,
float $cHeight,
float $cDepth,
int $sdW,
int $sdH,
int $sdD,
float $xPos,
float $yPos,
float $zPos,
float $xRot,
float $yRot,
float $zRot
)
{
polyCube -name $cubeName
-width ($cWidth)
-height ($cHeight)
-depth ($cDepth)
-subdivisionsWidth ($sdW)
-subdivisionsHeight ($sdH)
-subdivisionsDepth ($sdD);
move -r ($xPos) ($yPos) ($zPos);
rotate -r ($xRot) ($yRot) ($zRot);
}
bigCube("jeff",10,10,10,3,3,3,0,10,0,45,45,45); |

Procedure : Create lots
of any Cube
//--------------------------------------------------------------
//
// example 03 : Create many cubes, any size, position and
rotation
//
//--------------------------------------------------------------
proc ManyBigCube( string $cubeName,
int $numCubes,
float $randRadius
)
{
for($num=0;$num<=($numCubes);$num++)
{
vector $randSize=<<rand(1,10),rand(1,10),rand(1,10)>>;
vector $randPos=sphrand($randRadius);
vector $randRot=sphrand(180);
polyCube -name ($cubeName + $num)
-width ($randSize.x)
-height ($randSize.y)
-depth ($randSize.z);
move -r ($randPos.x) ($randPos.y) ($randPos.z);
rotate -r ($randRot.x) ($randRot.y) ($randRot.z);
}
}
ManyBigCube("rubble",10,20); |

Straight in at the deep
end
//--------------------------------------------------------------
//
// Create a window, buttons and procedures
//
//--------------------------------------------------------------
// create the
keyframe proc
proc superKeyer(int $choice){
string $sel[] = `ls -sl`;
for ($obj in $sel ) {
if ($choice == 1) setKeyframe -at "translateX";
if ($choice == 2) setKeyframe -at "translateY";
if ($choice == 3) setKeyframe -at "translateZ";
if ($choice == 4) setKeyframe -at "rotateX";
if ($choice == 5) setKeyframe -at "rotateY";
if ($choice == 6) setKeyframe -at "rotateZ";
}
}
// create the delete keyframe proc
// complete the following procedure
proc deleteKeyFrame(){
}
//Check for window and delete if needed
if (`window -exists EZkeyer` ) {
deleteUI -window EZkeyer;
}
// create variable to hold the window command.
All variables start with $ in MEL
// String variable are held inside single quotes
// command window and RMB > QuickHelp
// ui for the ezkeyer window [-title name of
win] [-wh width and height] [name of the win]
string $ezWindow = `window -title "EZKeyer"
-wh 128 256
EZkeyer`;
// define layout : 2 columns. The 1st column has
a width of 16 pixels
// [-nc Number of Colomns 2] [-cw column width
column num column width]
rowColumnLayout -numberOfColumns 2 -cw 1 16;
// column 1 column 2
// Don't forget the semicolon
// button -label "X" -c "superKeyer(1)"; text
-label "Translate X"
button -label "X" -c "superKeyer(1)"; text
-label "Translate X";
button -label "Y" -c "superKeyer(2)"; text
-label "Translate Y";
button -label "Z" -c "superKeyer(3)"; text
-label "Translate Z";
separator; separator;
separator; separator;
button -label "X" -c "superKeyer(4)"; text
-label "Rotate X";
button -label "Y" -c "superKeyer(5)"; text
-label "Rotate Y";
button -label "Z" -c "superKeyer(6)"; text
-label "Rotate Z";
// this will show the window
showWindow $ezWindow; |
Expression :
Bouncing Ball
//----------------------------------------------------------------
//
// An Expression to make a ball(polySphere) bounce
mathematically.
// No keyframes used.
//
//----------------------------------------------------------------
// Create a
polySphere with a radius approx 5
float $yvel;
float $ypos;
float $xvel;
float $xpos;
float $zvel;
float $zpos;
float $gravity;
float $myRadius;
float $dampening;
if (frame == 1)
{
$ypos=50;
setAttr pSphere1.translateY $ypos;
$xpos=0;
setAttr pSphere1.translateX $xpos;
$zpos=0;
setAttr pSphere1.translateZ $zpos;
$xvel=rand(-2.0,2.0);
$zvel=rand(-2.0,2.0);
$yvel=-2.0;
$gravity=2;
$dampening=rand(0.975,0.98);
$myRadius = `getAttr polySphere1.radius`;
}
$yvel-=$gravity;
$ypos+=$yvel;
$xpos+=$xvel;
$zpos+=$zvel;
setAttr pSphere1.translateY $ypos;
setAttr pSphere1.translateX $xpos;
setAttr pSphere1.translateZ $zpos;
if(`getAttr pSphere1.translateY` <= $myRadius)
{
setAttr pSphere1.translateY $myRadius;
$yvel=$yvel*(-1);
$xvel*=$dampening;
$yvel*=$dampening;
$zvel*=$dampening;
} |
|

open window and setting preference
delete/purge the windows preferences
windowPref -remove(r) name_of_window;
variables
int $myIntVar=10;
float $myFloatVar=3.12;
vector $myVectorVar=<<12.6,3.2,5.0>>;
string $myStringVar="Hello FridgeMonster!!";
int $myIntArray[]=..??
float $myFloatArray[]=...??
string $myStringArray[]=....??
How to create an Array of specifc size?
// declare an array of 11
elements
int $int_array[]
= {10,9,8,7,6,5,4,3,2,1,0};
How to find the size?
int $size = size($int_array);
How to add elements?
How to delete elements?
How to sort elements?
vector $locPos=<<locator1.tx,locator1.ty,locator1.tz>>;
vector $partPos=position;
if($partPos.y>$locPos.y)
{
lifespanPP=0;
}
Explain sin and cos
radians and degree
radians to degree conversions
for in
* create a scene with several spheres, cameras, locators and
lights. Select them...
string $eachElement;
string $selObjList[]=`ls -sl`; // put this line in long-hand
for($eachElement in $selObjList)
{
print("Element 1 is name_of_object");
}
//Note : comand node Type display node type
//must select shape node
//not the transform node
//RMB in Outliner window and click "Show Shapes"
string $allMeshes[]=`ls -type "mesh"`;
//note : do the same for cameras, splines, lights, ..
if(`window -exists meshUI==1`)
deleteUI meshUI;
window -title $allMeshes"-mbx 0 -mnb 0 meshUI;
columnLayhout -adj mainCol;
textScrollList -height 150 meshTSL;
for($eachMesh in $allMeshes)
{
textScrollList -e -append $eachMesh meshTSL;
}
Nested Loops 2
if(`window -exists sliderUI`)
{
deleteUI sliderUI;
}
window sliderUI;
columnLayout mainCol;
text -label "Keyable Attributes":";
string $selectedObjects[]=`ls -sl`;
for($eachObject in $selectedObjects)
{
string $keyAtt[]=`listAttr -keyable $eachObject`;
separator -width 400 -style "out";
text -label $eachObject;
for($eachKeyAttr in $keyAtt)
{
attrFieldSliderGrp -min 100 -max 100 -at ($eachObject + "."
+ $eachKeyAttr);
button -label "Keyframe" -width 100 -command ("setKeyframe "
+ $eachObject + "." + $eachKeyAttr);
}
}
showWindow sliderUI
//------------------------------------------------------------------------
//
// further explanation for example above longhand and
shorthand
//
//------------------------------------------------------------------------
// note : short version
listAttr -keyable `ls -sl`;
// note : long version
string $sel[]=`ls -sl`;
for($each in $sel)
{
string $keyableAtts[]=`list Attr -keyable $each`;
for($eachElement in $keyableAtts)
{
print($eachElement + " is a keyable element of " + $each +
"\n");
}
}
//------------------------------------------------------------------------
//
// separator styles
//
//------------------------------------------------------------------------
-style "none"
-style "single"
-style "double"
-style "singleDash"
-style "doubleDash"
-style "in"
-style "out"
//------------------------------------------------------------------------
//
// Variable Scope
//
//------------------------------------------------------------------------
// only exists inside the loop
for($x=0;$x<10;$x++)
{
print($x + "\n");
string $myText[]={"Hello"};
}
print $myText;
//result : Error : myText does not exists outside the loop
// check this : in my notes, but don't understand why..!!
string $myText[]={"hello mum"};
string $myText={"hello dad"};
//------------------------------------------------------------------------
//
// Renaming Procedure
//
//------------------------------------------------------------------------
global proc FM_renameAll(string $newName)
{
string $selObjects[]=`ls -sl`;
for($eachObject in $selObjects)
{
rename $eachObject ($newName + "_#");
}
}
renameAll(nastymonster);
// note : "_###" <- check this out ..!! what happens with
the padding..??
//------------------------------------------------------------------------
//
// Renaming UI
//
//------------------------------------------------------------------------
global proc fmRename()
{
if(`window -exists fmRenameUI`)
{
deleteUI fmRenameUI;
}
window -title "FM Object Renamer" -mxb off -mnb off
fmRenameUI;
columnLayout -adj on mainCol;
textScrollList -height 150 renameTSL;
button -label "GetObjects" -command "fmPopulateTSL" getButton;
text -label "New Name : ";
textField newNameTextField;
button -label "Rename" -command "fmRenameThis" renameButton;
populateTSL();
showWindow fmRenameUI;
}
global proc fmPopulateTSL()
{
textScrollList -edit -removeAll renameTSL;
string $selObject[]=`ls -sl`;
for($each in $selObject)
{
textScrollList -edit -append $each renameTSL;
}
}
global proc fmRenameThis()
{
string $newName=`textField -query -text newNameTextField`;
if($newName!="")
{
string $itemsInTSL[]=`textScrollList -query -allItems
renameTSL`;
for($eachItem in $itemsInTSL)
{
rename $eachItem ($newName + "_#");
}
populateTSL();
}
else
{
confirmDialog -title "Whoopsie..!!" -message "Please enter
new name for objects" -button "Cancel";
}
} |

//------------------------------------------------------------------------
//
// Create Extra Cameras
//
//------------------------------------------------------------------------
global proc fmAddCameras()
{
if(`window -exists allCamsUI`)
{
deleteUI allCamsUI;
}
window -title "FM Add Cameras" -wh 170 170 -mxb off -mnb off
allCamsUI;
columnLayout -adj on mainCol;
checkBox -label "Show/Hide Cameras" -onc ShowCameras -ofc
HideCameras showHideChkBox;
button -label "Create All" -c "fmCreateAllCams()";
separator -style "out" -height 10;
text -align "left" -label "Create Separately";
button -label "Back Camera" -c "fmCreateCam(1)";
button -label "Left Camera" -c "fmCreateCam(2)";
button -label "Bottom Camera" -c "fmCreateCam(3)";
HideCameras;
showWindow allCamsUI;
}
global proc fmCreateCam(int $CamChoice)
{
switch ($CamChoice)
{
case 1:
if(objExists("back"))
{
fmWinExists();
}
else
{
string $back[]=`camera -name back`;
viewSet -back $back[0];
rename "back1" "back";
hide back;
}
break;
case 2:
if(objExists("left"))
{
fmWinExists();
}
else
{
string $left[]=`camera -name left`;
viewSet -leftSide $left[0];
rename "left1" "left";
hide left;
}
break;
case 3:
if(objExists("bottom"))
{
fmWinExists();
}
else
{
string $bottom[]=`camera -name bottom`;
viewSet -bottom $bottom[0];
rename "bottom1" "bottom";
hide bottom;
}
break;
}
}
global proc fmWinExists()
{
confirmDialog -title "Whoopsie..!!" -message "This camera
already exists" -button "Cancel";
}
global proc fmCreateAllCams()
{
for($x=1;$x<4;$x++)
{
createCam($x);
print ($x + "\n");
}
} |

//------------------------------------------------------------------------
//
// Find the positions of 2 objects
//
//------------------------------------------------------------------------
global proc fmFindPos()
{
string $objselect[]=`ls -sl`;
for($eachObject in $objselect)
{
float $xpos=`getAttr ($eachObject + ".translateX")`;
float $ypos=`getAttr ($eachObject + ".translateY")`;
float $zpos=`getAttr ($eachObject + ".translateZ")`;
print($eachObject + " : x=" +
$xpos + " : y=" +
$ypos + " : z=" +
$zpos +
"\n");
}
}
fmFindPos(); |
//------------------------------------------------------------------------
//
// StairMaker beta0.0
//
//------------------------------------------------------------------------
global proc fmCreateLocator()
{
spaceLocator -p 0 0 0;
move -a 0 5 5;
spaceLocator -p 0 0 0;
move -a 0 5 -5;
select -d;
}
global proc fmFindPos()
{
float $stepWidth=10;
float $stepDepth=4;
float $stepHeight=1;
string $objselect[]=`ls -sl`;
float $xpos1=`getAttr ($objselect[0] + ".translateX")`;
float $ypos1=`getAttr ($objselect[0] + ".translateY")`;
float $zpos1=`getAttr ($objselect[0] + ".translateZ")`;
float $xpos2=`getAttr ($objselect[1] + ".translateX")`;
float $ypos2=`getAttr ($objselect[1] + ".translateY")`;
float $zpos2=`getAttr ($objselect[1] + ".translateZ")`;
float $distx=($xpos2-$xpos1);
float $disty=($ypos2-$ypos1);
float $distz=($zpos2-$zpos1);
for($x=0;$x<20;$x=$x+1)
{
polyCube -name ("newStep" + $x) -width $stepWidth -depth $stepDepth
-height $stepHeight;
move -absolute ((($distx/20)*$x)+$xpos1) ((($disty/20)*$x)+$ypos1)
((($distz/20)*$x)+$zpos1);
string $soldier[]=`ls -sl`;
select -r ($objselect[1]);
string $commander[]=`ls -sl`;
select -add $soldier;
print($commander);
print($soldier);
aimConstraint -offset 0 0 0
-weight 1
-aimVector 0 0 1
-upVector
0 1 0
-worldUpType "vector"
-worldUpVector 0 1 0
-skip x
-skip z;
select -r ($soldier[0] + "_aimConstraint1");
delete -constraints;
}
}
fmFindPos(); |

//------------------------------------------------------------------------
//
// fmCreatePrimitiveGeom
//
//------------------------------------------------------------------------
//Global Procedure to used
with GUI to create primitives:
global proc fmCreatePrimitiveGeom()
{
string $name = `textField -query -text "myField"`;
int $radio = `radioButtonGrp -query -select "myRadios"`;
int $checkTrans = `checkBox -query -value "myCheckTranslate"`;
int $checkRotate = `checkBox -query -value "myCheckRotate"`;
int $checkScale = `checkBox -query -value "myCheckScale"`;
int $checkDH = `checkBox -query -value "myCheckDeleteHistory"`;
int $checkTR = `checkBox -query -value "myCheckResetTrans"`;
string $names[];
string $type;
string $hd;
string $rt;
if ($radio == 3)
{
$type="cone";
$names=`polyCone -name $name
-axis 0 1 0
-radius 1
-height 2
-subdivisionsAxis 20
-subdivisionsHeight 1
-constructionHistory 1`;
}
else if ($radio == 2)
{
$type="cube";
$names=`polyCube -name $name
-width 2
-height 2
-depth 2
-subdivisionsX 1
-subdivisionsY 1
-subdivisionsZ 1
-axis 0 1 0
-createUVs 4
-constructionHistory 1`;
}
else
{
$type="sphere";
$names=`polySphere -name $name
-axis 0 1 0
-radius 1
-subdivisionsAxis 12
-subdivisionsHeight 6
-constructionHistory 1`;
}
vector $valsT;
vector $valsR;
vector $valsS;
if ($checkTrans == 1)
{
$valsT = `rand <<-10.0,-10.0,-10.0>> <<10.0,10.0,10.0>>`;
}
else
{
$valsT = <<0.0,0.0,0.0>>;
}
if ($checkRotate == 1)
{
$valsR = `rand <<-360.0,-360.0,-360.0>>
<<360.0,360.0,360.0>>`;
}
else
{
$valsR = <<0.0,0.0,0.0>>;
}
if ($checkScale == 1)
{
$valsS = `rand <<0.25,0.25,0.25>> <<2.5,2.5,2.5>>`;
}
else
{
$valsS = <<1.0,1.0,1.0>>;
}
setAttr($names[0] + ".t")($valsT.x) ($valsT.y) ($valsT.z);
setAttr($names[0] + ".r")($valsR.x) ($valsR.y) ($valsR.z);
setAttr($names[0] + ".s")($valsS.x) ($valsS.y) ($valsS.z);
if($checkDH == 1)
{
$hd="true";
delete -constructionHistory $names[0];
}
else
{
$hd="false";
}
if($checkTR == 1)
{
$rt="true";
makeIdentity -apply true -translate 1 -rotate 1 -scale 1
-normal 0 $names[0];
}
else
{
$rt="false";
}
string $print1=("//Result : " + $type + " named \"" +
$names[0] + "\" created");
string $print2=("Translation value : " + $valsT);
string $print3=("Rotation value : " + $valsR);
string $print4=("Scale value : " + $valsS);
string $print5=(" ");
string $print6=("History Deleted : " + $hd);
string $print7=("Transformations Reset : " + $rt);
textScrollList -edit -removeAll feedbackTSL;
textScrollList -edit -append $print1 feedbackTSL;
textScrollList -edit -append $print2 feedbackTSL;
textScrollList -edit -append $print3 feedbackTSL;
textScrollList -edit -append $print4 feedbackTSL;
textScrollList -edit -append $print5 feedbackTSL;
textScrollList -edit -append $print6 feedbackTSL;
textScrollList -edit -append $print7 feedbackTSL;
}
string $winName = "myWindow";
string $fieldName = "myField";
string $radioName = "myRadios";
string $checkNameTranslate = "myCheckTranslate";
string $checkNameRotate = "myCheckRotate";
string $checkNameScale = "myCheckScale";
string $checkNameDeleteHistory = "myCheckDeleteHistory";
string $checkNameResetTrans = "myCheckResetTrans";
string $textName = "myText";
if (`window -exists $winName`)
{
windowPref -remove $winName;
deleteUI $winName;
}
window -title "FM Primitive Creator" -widthHeight 300 390 $winName;
columnLayout -adj 1 ;
separator -width 300 -style "in";
text -label "[1]:Enter the Name of the Primitive" -align
"left";
textField -width 150 -text "name here" $fieldName;
separator -width 300 -style "in";
text -label "[2]:Select Primitive to Create" -align "left";
radioButtonGrp -select 0
-numberOfRadioButtons 3
-label "Types:"
-columnAlign 1 "left"
-columnWidth4 50 70 70 70
-labelArray3 "sphere" "cube" "cone"
$radioName;
separator -width 300 -style "in";
text -label "[3]:Randomise Primitive Transformations" -align
"left";
checkBox -label "Translate" -value 0 -align "left" $checkNameTranslate
;
checkBox -label "Rotation" -value 0 -align "left" $checkNameRotate
;
checkBox -label "Scale" -value 0 -align "left" $checkNameScale
;
separator -width 300 -style "in";
text -label "[4]:Cleaning Up" -align "left";
checkBox -label "Delete History" -value 0 -align "left" $checkNameDeleteHistory;
checkBox -label "Reset Transformations" -value 0 -align
"left" $checkNameResetTrans;
separator -width 300 -style "in";
button -label "Create Primitive" -width 100 -command "fmCreatePrimitiveGeom";
separator -width 300 -style "in";
text -label " ";
textScrollList -height 120 feedbackTSL;
showWindow $winName |

//------------------------------------------------------------------------
//
// fmArmRigger
//
//------------------------------------------------------------------------
This script creates and rigs
the shoulder, elbow and wrist controllers for a basic
arbitrary arm pose (non t-pose).
Note
: A huge thanks to Shih Ming Tay for showing me this rigging
technique.
step 1. Download the example
file below.
download scene file
(MAYA 8.5 .ma)
(right-click and save file. Rename file with .ma extension)
step 2. Copy the code below in
the MAYA script editor and run it. The fmArmRigger window
will appear (see image
below)
step 3. Enter name of the shoulder joint
step 4. Select the aim axis of the joint
(there is a Toggle Local Axis
Display button to help with this)
step 5. Click the
Create Arm Rig button. Finished.
Try Mirroring the arm joints
in MAYA and then applying the control rig with this script.
proc fmToggleLocalAxis()
{
string $startJoint = `textField -query -text "myField"`;
select -hierarchy $startJoint;
toggle -localAxis;
select -cl;
}
proc fmArmRigger()
{
int $radio = `radioButtonGrp -query -select "myRadios"`;
if(!($radio>0))
{
error "Please Select the Joint Aim Axis";
}
string $startJoint = `textField -query -text "myField"`;
select -r $startJoint;
string $shoulderGrp;
string $elbowGrp;
string $wristGrp;
string $shoulderControl;
string $elbowControl;
string $wristControl;
for($jcount=1;$jcount<4;$jcount++)
{
string $jointPosition[] =`ls -sl`;
string $circleName[]=`circle -c 0 0 0 -nr 1 0 0 -sw 360 -r 3
-d 3 -ut 0 -tol 0.01 -s 8 -ch 1`;
select -r $jointPosition[0];
select -tgl $circleName[0];
pointConstraint -offset 0 0 0 -weight 1;
select -r $jointPosition[0];
pickWalk -direction down;
select -tgl $circleName[0];
if ($radio == 1)
{
aimConstraint -offset 0 0 0
-weight 1
-aimVector 1 0 0
-upVector 0 1 0
-worldUpType "vector"
-worldUpVector 0 1 0;
}
else
{
aimConstraint -offset 0 0 0
-weight 1
-aimVector -1 0 0
-upVector 0 -1 0
-worldUpType "vector"
-worldUpVector 0 1 0;
}
select -r ($circleName[0] + "_pointConstraint1")
($circleName[0] + "_aimConstraint1") ;
doDelete;
select -r $circleName[0];
select -tgl $jointPosition[0];
orientConstraint -offset 0 0 0 -weight 1;
CreateEmptyGroup;
string $groupName[] =`ls -sl`;
select -r $circleName[0];
select -tgl $groupName[0];
parentConstraint -weight 1;
select -r ($groupName[0] + "_parentConstraint1") ;
doDelete;
select -r $circleName[0];
select -tgl $groupName[0];
parent;
rename ($groupName[0]) ($jointPosition[0] + "_group");
rename ($circleName[0]) ($jointPosition[0] + "_control");
if($jcount==1)
{
$shoulderGrp=($jointPosition[0] + "_group");
$shoulderControl=($jointPosition[0] + "_control");
}
else if($jcount==2)
{
$elbowGrp=($jointPosition[0] + "_group");
$elbowControl=($jointPosition[0] + "_control");
}
else
{
$wristGrp=($jointPosition[0] + "_group");
$wristControl=($jointPosition[0] + "_control");
}
select -r $jointPosition[0];
pickWalk -direction down;
}
print ("[1] " + $shoulderGrp + " : " + $shoulderControl +
"\n");
print ("[2] " + $elbowGrp + " : " + $elbowControl + "\n");
print ("[3] " + $wristGrp + " : " + $wristControl + "\n");
select -cl;
select -r $wristGrp;
select -tgl $elbowControl;
parent;
select -cl;
select -r $elbowGrp;
select -tgl $shoulderControl;
parent;
select -cl;
}
string $winName = "myWindow";
string $fieldName = "myField";
string $radioName = "myRadios";
if (`window -exists $winName`)
{
windowPref -remove $winName;
deleteUI $winName;
}
window -title "FM ArmRigger" -widthHeight 300 135 $winName;
columnLayout -adj 1 ;
separator -width 300 -height 6 -style "in";
text -label " Enter the Name of the Shoulder Joint" -align
"left";
textField -width 150 -text "shoulder joint name here" $fieldName;
separator -width 300 -height 6 -style "in";
text -label " Joint Axis Aim Direction" -align "left";
radioButtonGrp -select 0
-numberOfRadioButtons 2
-label " Axis"
-columnAlign 1 "left"
-columnWidth3 50 70 70
-labelArray2 "+X" "-X"
$radioName;
separator -width 300 -height 6 -style "in";
button -label "Toggle Local Axis Display" -width 100
-command "fmToggleLocalAxis";
separator -width 300 -height 6 -style "in";
button -label "Create Arm Rig" -width 100 -command "fmArmRigger";
showWindow $winName; |

////////////////////////////////////////////////////////////////////////////////////
//
// Script to list the the joints in a chain for a single
chainv eg. arm, leg or spline
//
////////////////////////////////////////////////////////////////////////////////////
proc string[] fmReverseArray(string
$array[])
{
string $revArray[];
int $arraySize=`size($array)`;
for($n = 0;$n<$arraySize;$n++)
{
$revArray[($arraySize-1-$n)]=$array[$n];
}
return $revArray;
}
proc fmLegRigger()
{
string $startJoint = `textField -query -text "myField"`;
select -r $startJoint;
// assign selection list to an array
string $sel[] = `ls -sl`;
// assign all the child, grandchild etc objects to an array
// unfortunately in MEL this is list in reverse order..!!
string $tmpJoints[] = `listRelatives -ad -type joint
$sel[0]`;
// Add the orginally selected joint to the end of the array
int $num=`size($tmpJoints)`;
$tmpJoints[$num]=$sel[0];
// reverse the array to the correct order
$listJoints=fmReverseArray( $tmpJoints
);
// print them out just to be sure..!!
for($count=0;$count<(size($listJoints));$count++)
{
print ($listJoints[$count] + "\n");
}
select -cl;
}
string $winName = "myWindow";
string $fieldName = "myField";
;
if (`window -exists $winName`)
{
windowPref -remove $winName;
deleteUI $winName;
}
window -title "FM Joint List" -widthHeight 300 128 $winName;
columnLayout -adj 1 ;
separator -width 300 -height 6 -style "in";
text -label " Enter the Name of the First Joint" -align
"left";
textField -width 150 -text "enter name of 1st joint here" $fieldName;
button -label "Toggle Local Axis Display" -width 100
-command "fmToggleLocalAxis";
separator -width 300 -height 6 -style "in";
button -label "List Joint Chain" -width 100 -command "fmLegRigger";
showWindow $winName; |