Sunday, 6 October 2013

Maya Pie Maker


I have made a little script for Maya that creates slices of a pie-chart. Not sure what use it is to anyone but here it is:
////////////////////////////////////////////////

// SCRIPT TO CREATE PIE CHARTS :)

///////////////////////////////////////////////

global proc mkPie(){

float $percent = `floatField -q -value itemPercent`;

$name = `textField -q -text item`;

$sections = `intField -q -value itemSections`;

//setAttr textForBevel1.text -type "string" ($percent+"%");

$deg = ($percent/100);

$degree = (360 * $deg);

cylinder -ch on -o on -ax 0 1 0 -r 3 -s $sections -hr 0 -n $name -ssw 0deg -esw ($degree+"deg");

nurbsPrimitiveCap 3 1 1;

parent -w bottomCap1 ;

delete $name;

nurbsToPoly -mnd 1 -ch 1 -f 2 -pt 1 -pc 200 -chr 0.1 -ft 0.01 -mel 0.001 -d 0.1 -ut 1 -un 10 -vt 1 -vn ($sections*3) -uch 0 -ucr 0 -cht 0.2 -es 0 -ntr 0 -mrt 0 -uss 1 "bottomCap1";

delete bottomCap1;

string $polyName = ($name+"_mesh");

rename "nurbsToPoly1" $polyName;

setAttr ($polyName+".translateY") 3;

makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $polyName;

polyExtrudeFacet -constructionHistory 1 -keepFacesTogether 1 -pvx 1.239527732 -pvy 0 -pvz 1.499420881 -divisions 10 -twist 0 -taper 1 -off 0 -thickness 0 -smoothingAngle 30 $polyName;

setAttr "polyExtrudeFace1.localTranslate" -type double3 0 0 -1.940407 ;

select -r $polyName; DeleteHistory;

displaySmoothness -divisionsU 3 -divisionsV 3 -pointsWire 16 -pointsShaded 4 -polygonObject 3;

subdivDisplaySmoothness -smoothness 3;

select -cl;

}

global proc mkEnv(){

polyPlane -n myPlane -sx 10 -sy 10 -h 50 -w 50 ;

displaySmoothness -divisionsU 3 -divisionsV 3 -pointsWire 16 -pointsShaded 4 -polygonObject 3;

subdivDisplaySmoothness -smoothness 3;

setAttr "myPlane.overrideEnabled" 1;

setAttr "myPlane.overrideShading" 1;

setAttr "myPlane.overrideDisplayType" 2;

nonLinear -type bend -lowBound 0 -highBound 1 -curvature 1.6;

setAttr "bend1Handle.rotateZ" 90;

select "bend1Handle" myPlane; group -n "environment";

setAttr "environment.translateX" -5;

}

global proc mkPieWindow(){

if (`window -exists pieUI`){

deleteUI pieUI;

}

string $window = `window -title "PIE MAKER :)" -widthHeight 200 300 pieUI`;



columnLayout -adjustableColumn true;

text -label "Percent";

string $itemPercent = `floatField -value 10 itemPercent`;

text -label "Item Name";

string $item = `textField -text "Piece_0" item`;

text -label "Item Sections";

string $sections = `intField -v 4 itemSections`;

button -label "Make Me - go on do it :)" -command "mkPie";

button -label "Environment" -command "mkEnv";

setParent ..;

showWindow $window;

}