Monday, 28 February 2011

Winrar just finished the min max UI its all now based around variables the user has input and has fully broken away from hard coded values, those values are still coded but now they are defaults for the UI as apposed to the only value usable, the break away from hard code to a fully UI orientated script probably means this is now in beta, but I wont class it as such, until I've created an origin lock on each axis, which in theory will be pretty straight forward but may require more than a few sleepless nights, by and large all the functions currently doable are finalised including the GUI theres a few minor graphical outputs i wish to implement and rearrange the GUI slightly, which i shall change before i continue on with the things i wish to include so it feels complete and easy to use. Also with code formating and the few notes included it hit over 500 lines! 


CODE;

proc sc_gui()
{
if (`window -exists "sc_gui"`) deleteUI "sc_gui";
window -w 150 -h 300 -t "Locator Randomiser" -
maximizeButton false -minimizeButton false sc_gui;
columnLayout;
string $sel[] = (`ls -sl`);
separator;
separator;
textFieldButtonGrp -label "Object:"
-text $sel
-buttonLabel "<<<"
-cw3 50 165 10
-ct3 "left" "both" "left"
-buttonCommand "sc_getObj()" selObj;
separator;
separator;
separator -style "double" -w 265;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 10
-columnWidth 3 5
-columnWidth 4 45
-columnWidth 5 5
-columnWidth 6 130
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0;
button -vis 0;
button -vis 0;
button -vis 0;
button -vis 0;
text "Frame Settings";
button -vis 0;
button -vis 0;
button -vis 0;
button -vis 0;
setParent..;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 5
-columnWidth 3 5
-columnWidth 4 100
-columnWidth 5 5
-columnWidth 6 5
-columnWidth 7 5
-columnWidth 8 100
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0;
button -vis 0;
button -vis 0;
textFieldGrp -l "Start:" -cw2 50 165 -text 1 start;
button -vis 0;
button -vis 0;
button -vis 0;
textFieldGrp -l "Min:" -cw2 50 165 -text 1 minFrame;
button -vis 0;
button -vis 0;
setParent..;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 5
-columnWidth 3 5
-columnWidth 4 100
-columnWidth 5 5
-columnWidth 6 5
-columnWidth 7 5
-columnWidth 8 100
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0;
button -vis 0;
button -vis 0;
textFieldGrp -l "Finish:" -cw2 50 165 -text 100 finish;
button -vis 0;
button -vis 0;
button -vis 0;
textFieldGrp -l "Max:" -cw2 50 165 -text 10 maxFrame;
button -vis 0;
button -vis 0;
setParent..;
separator;
separator;
separator;
separator;separator;
separator;
separator -style "double" -w 265;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 10
-columnWidth 3 5
-columnWidth 4 45
-columnWidth 5 5
-columnWidth 6 130
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0;
button -vis 0;
button -vis 0;
text "Min";
button -vis 0;
text "Movement Parameters";
button -vis 0;
text "Max";
button -vis 0;
button -vis 0;
setParent ..;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 10
-columnWidth 3 5
-columnWidth 4 45
-columnWidth 5 5
-columnWidth 6 130
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0; //1
text "X:"; //2
button -vis 0; //3
textField -text -10 -aie true -ec sc_minMaxUpdateX minFltSldX;//4
button -vis 0;//5
floatSlider -min -10 -max 10 tranX;//6
button -vis 0;//7
textField -text 10 -aie true -ec sc_minMaxUpdateX maxFltSldX;//8
button -vis 0 ;//9
button -vis 0;//10
button -vis 0;//11
setParent..;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 10
-columnWidth 3 5
-columnWidth 4 45
-columnWidth 5 5
-columnWidth 6 130
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0;//1
button -vis 0;//2
button -vis 0;//3
text "Random:";//4
button -vis 0;//5
checkBox -l " " randChkX;//6
button -vis 0;//7
button -vis 0;//8
button -vis 0;//9
button -vis 0;//10
button -vis 0;//11
setParent..;
separator;
separator;
separator -style "single" -w 265;
separator;
separator;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 10
-columnWidth 3 5
-columnWidth 4 45
-columnWidth 5 5
-columnWidth 6 130
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0; //1
text "Y:"; //2
button -vis 0; //3
textField -text -10 -aie true -ec sc_minMaxUpdateY minFltSldY;//8//4
button -vis 0;//5
floatSlider -min -10 -max 10 tranY;//6
button -vis 0;//7
textField -text 10 -aie true -ec sc_minMaxUpdateY maxFltSldY;//8
button -vis 0 ;//9
button -vis 0;//10
button -vis 0;//11
setParent..;
rowColumnLayout -numberOfColumns 9
-columnWidth 1 5
-columnWidth 2 50
-columnWidth 3 5
-columnWidth 4 20
-columnWidth 5 45
-columnWidth 6 75
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
;
button -vis 0;//1
text "Random:";//2
button -vis 0;//3
checkBox -l " Y" randChkY;//4
button -vis 0;//5
button -vis 0;//6
button -vis 0;//7
button -vis 0;//8
button -vis 0;//9
setParent..;
separator;
separator;
separator -style "single" -w 265;
separator;
separator;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 10
-columnWidth 3 5
-columnWidth 4 45
-columnWidth 5 5
-columnWidth 6 130
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0; //1
text "Z:"; //2
button -vis 0; //3
textField -text -10 -aie true -ec sc_minMaxUpdateZ minFltSldZ;//4
button -vis 0;//5
floatSlider -min -10 -max 10 tranZ;//6
button -vis 0;//7
textField -text 10 -aie true -ec sc_minMaxUpdateZ maxFltSldZ;//8
button -vis 0 ;//9
button -vis 0;//10
button -vis 0;//11
setParent..;
rowColumnLayout -numberOfColumns 9
-columnWidth 1 5
-columnWidth 2 50
-columnWidth 3 5
-columnWidth 4 20
-columnWidth 5 45
-columnWidth 6 75
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
;
button -vis 0;//1
text "Random:";//2
button -vis 0;//3
checkBox -l " Z" randChkZ;//4
button -vis 0;//5
button -vis 0;//6
button -vis 0;//7
button -vis 0;//8
button -vis 0;//9
setParent..;
separator;
separator;
separator -style "single" -w 265;
separator;
separator;
rowColumnLayout -numberOfColumns 3;
button -vis 0 -w 160;
button -l "Key" -c sc_frameCount;
button -vis 0;
setParent ..;
separator;
separator;
showWindow "sc_gui";
}
proc sc_getObj()
{
string $sel[] = (`ls -sl`);
string $firstObj = $sel[0];
textFieldButtonGrp -edit -text $firstObj selObj;
print $firstObj;
}
proc sc_applyMinMax()
{
int $minX = (`textField -query -text minFltSldX`);
int $maxX = (`textField -query -text maxFltSldX`);
print ($minX + "\n");
print ($maxX + "\n\n");
}
proc sc_minMaxUpdateX()
{
float $minX;
float $maxX;
$minX = (`textField -q -text minFltSldX`);
$maxX = (`textField -q -text maxFltSldX`);
floatSlider -edit -min $minX -max $maxX tranX;
}
proc sc_minMaxUpdateY()
{
float $minY;
float $maxY;
$minY = (`textField -q -text minFltSldY`);
$maxY = (`textField -q -text maxFltSldY`);
floatSlider -edit -min $minY -max $maxY tranY;
}
proc sc_minMaxUpdateZ()
{
float $minZ;
float $maxZ;
$minZ = (`textField -q -text minFltSldZ`);
$maxZ = (`textField -q -text maxFltSldZ`);
floatSlider -edit -min $minZ -max $maxZ tranZ;
}
proc sc_frameCount()
{
int $start = (`textFieldGrp -query -text start`);
int $end = (`textFieldGrp -query -text finish`);
int $min = (`textFieldGrp -query -text minFrame`);
int $max = (`textFieldGrp -query -text maxFrame`);
int $randMoveX;
int $randMoveY;
int $randMoveZ;
string $objAttrX;
string $objAttrY;
string $objAttrZ;
int $finalMoveX;
int $finalMoveY;
int $finalMoveZ;
int $objAttrGetX;
int $objAttrGetY;
int $objAttrGetZ;
string $sel[] = (`select`);
string $Ty = "ty";
int $currentFrame = $start;
for ($currentFrame > $start; $currentFrame < $end;)
{
int $randGen = rand($min,$max);
string $selObj = (`textFieldButtonGrp -query -text selObj`);
int $minFltSldX = (`textField -q -text minFltSldX`);
int $minFltSldY = (`textField -q -text minFltSldY`);
int $minFltSldZ = (`textField -q -text minFltSldZ`);
int $maxFltSldX = (`textField -q -text maxFltSldX`);
int $maxFltSldY = (`textField -q -text maxFltSldY`);
int $maxFltSldZ = (`textField -q -text maxFltSldZ`);
currentTime -edit $currentFrame;
$currentFrame = ($currentFrame + $randGen);
//~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~X~
//~~~~~~~~~~~~~~~~~~~~~~
if (`checkBox -q -v randChkX`)
{
$randMoveX = rand($minFltSldX,$maxFltSldX);
}
else
{
$randMoveX = (`floatSlider -query -value tranX`);
}
$objAttrX = $selObj + ".translateX";
$objAttrGetX = `getAttr $objAttrX`;
$finalMoveX = ($objAttrGetX + $randMoveX);
setAttr $objAttrX $finalMoveX;
//~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~Y~
//~~~~~~~~~~~~~~~~~~~~~~
if (`checkBox -q -v randChkY`)
{
$randMoveY = rand($minFltSldY,$maxFltSldY);
}
else
{
$randMoveY = (`floatSlider -query -value tranY`);
}
$objAttrY = $selObj + ".translateY";
$objAttrGetY = `getAttr $objAttrY`;
$finalMoveY = ($objAttrGetY + $randMoveY);
setAttr $objAttrY $finalMoveY;
//~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~Z~
//~~~~~~~~~~~~~~~~~~~~~~
if (`checkBox -q -v randChkZ`)
{
$randMoveZ = rand($minFltSldZ,$maxFltSldZ);
}
else
{
$randMoveZ = (`floatSlider -query -value tranZ`);
}
$objAttrZ = $selObj + ".translateZ";
$objAttrGetZ = `getAttr $objAttrZ`;
$finalMoveZ = ($objAttrGetZ + $randMoveZ);
setAttr $objAttrZ $finalMoveZ;
//~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~End~
//~~~~~~~~~~~~~~~~~~~~~~
setKeyframe `textFieldButtonGrp -query -text selObj`;
}
}
sc_gui()

Saturday, 26 February 2011

Today I gave myself a headache, but fix'd an issue that came about when I added in a couple IF statements, in short;

currentTime -edit $currentFrame;
$currentFrame = ($currentFrame + $randGen);
setKeyframe `textFieldButtonGrp -query -text selObj`;

is wrong, it should be;

currentTime -edit $currentFrame;
$currentFrame = ($currentFrame + $randGen);
IF()
SETATTR
setKeyframe `textFieldButtonGrp -query -text selObj`;

what it was doing was cycling through the FOR loop and not applying anything but keyframing it none the less,  took me ages to notice what it was doing =/

Next I'll need to go in and change the INT's to FLOAT's as I switched them around during debugging.
but it now has a properly random function, inwhich it will randomly keyframe random movements along the different axis, or randomly keyframe a set movement along the different axis. Next piece of functionality will be to make the min max for the axis affect the sliders, then i'll work on origin lock.

GUI;




CODE;

proc sc_gui()
{
if (`window -exists "sc_gui"`) deleteUI "sc_gui";
window -w 150 -h 300 -t "Locator Randomiser" -
maximizeButton false -minimizeButton false sc_gui;
columnLayout;
string $sel[] = (`ls -sl`);
separator;
separator;
textFieldButtonGrp -label "Object:"
-text $sel
-buttonLabel "<<<"
-cw3 50 165 10
-ct3 "left" "both" "left"
-buttonCommand "sc_getObj()" selObj;
separator;
separator;
separator -style "double" -w 260;
separator;
separator;
rowColumnLayout -numberOfColumns 1
-columnWidth 1 260;
text -al "left" " Frame Settings:";
setParent ..;
separator;
separator;
textFieldGrp -l "Start:"
-cw2 50 165 -text 1 start;
textFieldGrp -l "Finish:"
-cw2 50 165 -text 100 finish;
separator;
separator;
textFieldGrp -l "Min:"
-cw2 50 165 -text 1 minFrame;
textFieldGrp -l "Max:"
-cw2 50 165 -text 10 maxFrame;
separator;
separator;separator;
separator;
separator -style "double" -w 260;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 10
-columnWidth 3 5
-columnWidth 4 45
-columnWidth 5 5
-columnWidth 6 130
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0;
button -vis 0;
button -vis 0;
text "Min";
button -vis 0;
text "Movement Parameters";
button -vis 0;
text "Max";
button -vis 0;
button -vis 0;
setParent ..;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 10
-columnWidth 3 5
-columnWidth 4 45
-columnWidth 5 5
-columnWidth 6 130
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0; //1
text "X:"; //2
button -vis 0; //3
textField -text -10 minFltSldX;//4
button -vis 0;//5
floatSlider -min -10 -max 10 tranX;//6
button -vis 0;//7
textField -text 10 maxFltSldX;//8
button -vis 0 ;//9
button -vis 0;//10
button -vis 0;//11
setParent..;
rowColumnLayout -numberOfColumns 9
-columnWidth 1 5
-columnWidth 2 50
-columnWidth 3 5
-columnWidth 4 20
-columnWidth 5 45
-columnWidth 6 75
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
;
button -vis 0;//1
text "Random:";//2
button -vis 0;//3
checkBox -l " x" randChkX;//4
button -vis 0;//5
button -vis 0;//6
button -vis 0;//7
button -l "Apply";//8
button -vis 0;//9
setParent..;
separator;
separator;
separator -style "single" -w 260;
separator;
separator;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 10
-columnWidth 3 5
-columnWidth 4 45
-columnWidth 5 5
-columnWidth 6 130
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0; //1
text "Y:"; //2
button -vis 0; //3
textField -text -10 minFltSldY;//4
button -vis 0;//5
floatSlider -min -10 -max 10 tranY;//6
button -vis 0;//7
textField -text 10 maxFltSldY;//8
button -vis 0 ;//9
button -vis 0;//10
button -vis 0;//11
setParent..;
rowColumnLayout -numberOfColumns 9
-columnWidth 1 5
-columnWidth 2 50
-columnWidth 3 5
-columnWidth 4 20
-columnWidth 5 45
-columnWidth 6 75
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
;
button -vis 0;//1
text "Random:";//2
button -vis 0;//3
checkBox -l " Y" randChkY;//4
button -vis 0;//5
button -vis 0;//6
button -vis 0;//7
button -l "Apply";//8
button -vis 0;//9
setParent..;
separator;
separator;
separator -style "single" -w 260;
separator;
separator;
rowColumnLayout -numberOfColumns 11
-columnWidth 1 5
-columnWidth 2 10
-columnWidth 3 5
-columnWidth 4 45
-columnWidth 5 5
-columnWidth 6 130
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
-columnWidth 10 5
-columnWidth 11 5
;
button -vis 0; //1
text "Z:"; //2
button -vis 0; //3
textField -text -10 minFltSldZ;//4
button -vis 0;//5
floatSlider -min -10 -max 10 tranZ;//6
button -vis 0;//7
textField -text 10 maxFltSldZ;//8
button -vis 0 ;//9
button -vis 0;//10
button -vis 0;//11
setParent..;
rowColumnLayout -numberOfColumns 9
-columnWidth 1 5
-columnWidth 2 50
-columnWidth 3 5
-columnWidth 4 20
-columnWidth 5 45
-columnWidth 6 75
-columnWidth 7 5
-columnWidth 8 45
-columnWidth 9 5
;
button -vis 0;//1
text "Random:";//2
button -vis 0;//3
checkBox -l " Z" randChkZ;//4
button -vis 0;//5
button -vis 0;//6
button -vis 0;//7
button -l "Apply";//8
button -vis 0;//9
setParent..;
separator;
separator;
separator -style "single" -w 260;
separator;
separator;
rowColumnLayout -numberOfColumns 3;
button -vis 0 -w 160;
button -l "Key" -c sc_frameCount;
button -vis 0;
setParent ..;
separator;
separator;
showWindow "sc_gui";
}
proc sc_getObj()
{
string $sel[] = (`ls -sl`);
string $firstObj = $sel[0];
textFieldButtonGrp -edit -text $firstObj selObj;
print $firstObj;
}
proc sc_frameCount()
{
int $start = (`textFieldGrp -query -text start`);
int $end = (`textFieldGrp -query -text finish`);
int $min = (`textFieldGrp -query -text minFrame`);
int $max = (`textFieldGrp -query -text maxFrame`);
int $randMoveX;
int $randMoveY;
int $randMoveZ;
string $objAttrX;
string $objAttrY;
string $objAttrZ;
int $finalMoveX;
int $finalMoveY;
int $finalMoveZ;
int $objAttrGetX;
int $objAttrGetY;
int $objAttrGetZ;
string $sel[] = (`select`);
string $Ty = "ty";
int $currentFrame = $start;
for ($currentFrame > $start; $currentFrame < $end;)
{
int $randGen = rand($min,$max);
string $selObj = (`textFieldButtonGrp -query -text selObj`);
int $minFltSldX = (`textField -q -text minFltSldX`);
int $minFltSldY = (`textField -q -text minFltSldY`);
int $minFltSldZ = (`textField -q -text minFltSldZ`);
int $maxFltSldX = (`textField -q -text maxFltSldX`);
int $maxFltSldY = (`textField -q -text maxFltSldY`);
int $maxFltSldZ = (`textField -q -text maxFltSldZ`);
currentTime -edit $currentFrame;
$currentFrame = ($currentFrame + $randGen);
//~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~X
//~~~~~~~~~~~~~~~~~~~~~
if (`checkBox -q -v randChkX`)
{
$randMoveX = rand($minFltSldX,$maxFltSldX);
}
else
{
$randMoveX = (`floatSlider -query -value tranX`);
}
$objAttrX = $selObj + ".translateX";
$objAttrGetX = `getAttr $objAttrX`;
$finalMoveX = ($objAttrGetX + $randMoveX);
setAttr $objAttrX $finalMoveX;
//~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~Y
//~~~~~~~~~~~~~~~~~~~~~
if (`checkBox -q -v randChkY`)
{
$randMoveY = rand($minFltSldY,$maxFltSldY);
}
else
{
$randMoveY = (`floatSlider -query -value tranY`);
}
$objAttrY = $selObj + ".translateY";
$objAttrGetY = `getAttr $objAttrY`;
$finalMoveY = ($objAttrGetY + $randMoveY);
setAttr $objAttrY $finalMoveY;
//~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~Z
//~~~~~~~~~~~~~~~~~~~~~
if (`checkBox -q -v randChkZ`)
{
$randMoveZ = rand($minFltSldZ,$maxFltSldZ);
}
else
{
$randMoveZ = (`floatSlider -query -value tranZ`);
}
$objAttrZ = $selObj + ".translateZ";
$objAttrGetZ = `getAttr $objAttrZ`;
$finalMoveZ = ($objAttrGetZ + $randMoveZ);
setAttr $objAttrZ $finalMoveZ;
//~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~End
//~~~~~~~~~~~~~~~~~~~~~
setKeyframe `textFieldButtonGrp -query -text selObj`;
}
}
sc_gui()

Thursday, 24 February 2011

Today we dine in MEL Cont.

So today I set about adding some extra functionality, mainly a way to choose wheather or not to have the amount an object moves random or not, i've got as far as the GUI and a rough IF statement, that basicly reads, IF the box is checked then print "test"; else do what your sposed to, im undecided if the code for this should check all the boxes at once, or one by one, it would probably better to break the main FOR loop down into the the three main sections (x,y and z), that way it can differinciate between the 3 different values, were as if I make the check outside the FOR loop in the form of a IF statement, i'll still have to break them appart later. probably better logic to do it seperatly.


Heres the GUI;


 And the code (most of this is GUI orientated);
sc_gui();
proc sc_gui()
{
if (`window -exists "sc_gui"`) deleteUI "sc_gui";
window -w 150 -h 300 -t "Locator Randomiser" -

maximizeButton false -minimizeButton false sc_gui;
columnLayout;
string $sel[] = (`ls -sl`);
separator;
separator;
textFieldButtonGrp -label  "Object:"
-text $sel
-buttonLabel "<<<"
-cw3 50 165 10
-ct3 "left" "both" "left"
-buttonCommand "sc_getObj()" selObj;
separator;
separator;
separator -style "double" -w 260;
separator;
separator;
    rowColumnLayout -numberOfColumns 1
            -columnWidth 1 260;
        text -al "left" "      Frame Settings:";

    setParent ..;
separator;
separator;
textFieldGrp -l "Start:"
-cw2 50 165 -text 1 start;
textFieldGrp -l "Finish:"
-cw2 50 165 -text 100 finish;
separator;
separator;
textFieldGrp -l "Min:"
-cw2 50 165 -text 1 minFrame;
textFieldGrp -l "Max:"
-cw2 50 165 -text 10 maxFrame;
separator;
separator;separator;
separator;
separator -style "double" -w 260;

    rowColumnLayout -numberOfColumns 11
        -columnWidth 1 5
        -columnWidth 2 10
        -columnWidth 3 5
        -columnWidth 4 45      
        -columnWidth 5 5
        -columnWidth 6 130
        -columnWidth 7 5
        -columnWidth 8 45
        -columnWidth 9 5
        -columnWidth 10 5
        -columnWidth 11 5
        ;
            button -vis 0;
            button -vis 0;
            button -vis 0;
            text "Min";
            button -vis 0;
            text "Movement Parameters";
            button -vis 0;
            text "Max";
            button -vis 0;
            button -vis 0;
           
           
           
                       
            setParent ..;
    rowColumnLayout -numberOfColumns 11
        -columnWidth 1 5
        -columnWidth 2 10
        -columnWidth 3 5
        -columnWidth 4 45      
        -columnWidth 5 5
        -columnWidth 6 130
        -columnWidth 7 5
        -columnWidth 8 45
        -columnWidth 9 5
        -columnWidth 10 5
        -columnWidth 11 5
        ;
            button -vis 0; //1
            text "X:"; //2
            button -vis 0;    //3
            textField;//4
            button -vis 0;//5
        floatSlider   -min -10 -max 10 tranX;//6
            button -vis 0;//7
            textField;//8
            button -vis 0 ;//9
            button -vis 0;//10
            button -vis 0;//11
        setParent..;



            rowColumnLayout -numberOfColumns 9
                -columnWidth 1 5
                -columnWidth 2 50
                -columnWidth 3 5
                -columnWidth 4 20      
                -columnWidth 5 45
                -columnWidth 6 75
                -columnWidth 7 5
                -columnWidth 8 45
                -columnWidth 9 5
                ;
               
            button -vis 0;//1
            text "Random:";//2
            button -vis 0;//3
            checkBox  -l " x" randChkX;//4
            button -vis 0;//5
            button -vis 0;//6
            button -vis 0;//7
            button -l "Apply";//8
            button -vis 0;//9
           
        setParent..;
separator;
separator;
separator -style "single" -w 260;
separator;
separator;



    rowColumnLayout -numberOfColumns 11
        -columnWidth 1 5
        -columnWidth 2 10
        -columnWidth 3 5
        -columnWidth 4 45      
        -columnWidth 5 5
        -columnWidth 6 130
        -columnWidth 7 5
        -columnWidth 8 45
        -columnWidth 9 5
        -columnWidth 10 5
        -columnWidth 11 5
        ;
            button -vis 0; //1
            text "Y:"; //2
            button -vis 0;    //3
            textField;//4
            button -vis 0;//5
        floatSlider   -min -10 -max 10 tranY;//6
            button -vis 0;//7
            textField;//8
            button -vis 0 ;//9
            button -vis 0;//10
            button -vis 0;//11
        setParent..;


            rowColumnLayout -numberOfColumns 9
                -columnWidth 1 5
                -columnWidth 2 50
                -columnWidth 3 5
                -columnWidth 4 20      
                -columnWidth 5 45
                -columnWidth 6 75
                -columnWidth 7 5
                -columnWidth 8 45
                -columnWidth 9 5
                ;
               
            button -vis 0;//1
            text "Random:";//2
            button -vis 0;//3
            checkBox  -l " Y" randChkY;//4
            button -vis 0;//5
            button -vis 0;//6
            button -vis 0;//7
            button -l "Apply";//8
            button -vis 0;//9
           
        setParent..;
separator;
separator;
separator -style "single" -w 260;
separator;
separator;
          
           
    rowColumnLayout -numberOfColumns 11
        -columnWidth 1 5
        -columnWidth 2 10
        -columnWidth 3 5
        -columnWidth 4 45      
        -columnWidth 5 5
        -columnWidth 6 130
        -columnWidth 7 5
        -columnWidth 8 45
        -columnWidth 9 5
        -columnWidth 10 5
        -columnWidth 11 5
        ;
            button -vis 0; //1
            text "Z:"; //2
            button -vis 0;    //3
            textField;//4
            button -vis 0;//5
        floatSlider   -min -10 -max 10 tranZ;//6
            button -vis 0;//7
            textField;//8
            button -vis 0 ;//9
            button -vis 0;//10
            button -vis 0;//11
        setParent..;


            rowColumnLayout -numberOfColumns 9
                -columnWidth 1 5
                -columnWidth 2 50
                -columnWidth 3 5
                -columnWidth 4 20      
                -columnWidth 5 45
                -columnWidth 6 75
                -columnWidth 7 5
                -columnWidth 8 45
                -columnWidth 9 5
                ;
               
            button -vis 0;//1
            text "Random:";//2
            button -vis 0;//3
            checkBox  -l " Z" randChkZ;//4
            button -vis 0;//5
            button -vis 0;//6
            button -vis 0;//7
            button -l "Apply";//8
            button -vis 0;//9
           
        setParent..;
separator;
separator;
separator -style "single" -w 260;
separator;
separator;



 rowColumnLayout -numberOfColumns 3;
        button -vis 0 -w 160;
        button -l "Key" -c sc_frameCount;
        button -vis 0;

    setParent ..;
   
separator;
separator;
showWindow "sc_gui";

}

proc sc_getObj()
{
string $sel[] = (`ls -sl`);
string $firstObj = $sel[0];
textFieldButtonGrp -edit -text $firstObj selObj;
print $firstObj;
}

proc sc_frameCount()

{
int $start = (`textFieldGrp -query -text start`);
int $end = (`textFieldGrp -query -text finish`);
int $min = (`textFieldGrp -query -text minFrame`);
int $max = (`textFieldGrp -query -text maxFrame`);
string $sel[] = (`select`);
string $Ty = "ty";
int $randX = (`checkBox -query -v randChkX`);
int $randY = (`checkBox -query -v randChkY`);
int $randZ = (`checkBox -query -v randChkZ`);
$currentFrame = $start;

if($randX == 1 || $randY == 1 || $randZ == 1)
    {
    print "test";
    }
else{
    for ($currentFrame > $start; $currentFrame <

$end;)
    {   
    int $randGen = rand($min,$max);
    string $selObj = (`textFieldButtonGrp -query -text

selObj`);
    float $randMoveX = (`floatSlider -query -value

tranX`);
    float $randMoveY = (`floatSlider -query -value

tranY`);
    float $randMoveZ = (`floatSlider -query -value

tranZ`);
   
    string $objAttrX = $selObj + ".translateX";
    string $objAttrY = $selObj + ".translateY";
    string $objAttrZ = $selObj + ".translateZ";
   
    int $objAttrGetX = `getAttr $objAttrX`;
    int $objAttrGetY = `getAttr $objAttrY`;
    int $objAttrGetZ = `getAttr $objAttrZ`;
   
    int $finalMoveX = ($objAttrGetX + $randMoveX);
    int $finalMoveY = ($objAttrGetY + $randMoveY);
    int $finalMoveZ = ($objAttrGetZ + $randMoveZ);
   
   
   
    $currentFrame = ($currentFrame + $randGen);
        currentTime -edit $currentFrame;
        setAttr $objAttrX $finalMoveX;
        setAttr $objAttrY $finalMoveY;
        setAttr $objAttrZ $finalMoveZ;
        print ($currentFrame + "\n");       
        print ($randMoveX + "\n");
        print ($randMoveY + "\n");
        print ($randMoveZ + "\n");
        setKeyframe `textFieldButtonGrp -query

-text selObj`;
    }       
    }


sc_gui();

Wednesday, 23 February 2011

Today we dine in MEL

So today I hit a checkpoint with my script, and HAVE A VIDEO!

VIDEO;
video
Awesome, so what does it do, why is it a checkpoint etc. at the moment, all it does is move things along different axis, at random points between a user input time range. it mimics speed by changing the space between the keyframes. i'll figure out how to alter the distance automaticaly later on. It's a checkpoint because the sliders now work, the object select button works and the range is input by the user, plus the GUI looks perty, it will be rearranged to look better and the sections more logical. but other than that not a bad start.

GUI;






CODE;

proc sc_gui()

{
if (`window -exists "sc_gui"`) deleteUI "sc_gui";
window -w 150 -h 300 -t "Randomizer" -maximizeButton false -minimizeButton false sc_gui;
columnLayout;
separator;
separator;
textFieldButtonGrp -label "Object:"
-text ""
-buttonLabel "<<<"
-cw3 50 165 10
-ct3 "left" "both" "left"
-buttonCommand "sc_getObj()" selObj;
textFieldGrp -l "Start:"
-cw2 50 165 start;
textFieldGrp -l "Finish:"
-cw2 50 165 finish;
separator;
separator;
separator -style "double" -w 260;
separator;
separator;
checkBoxGrp -l "Random: "
-cw2 50 165;
separator;
separator;
floatSliderGrp -l "x "
-cw2 40 165 -min -10 -max 10 tranX;
floatSliderGrp -l "y "
-cw2 40 165 -min -10 -max 10 tranY;
floatSliderGrp -l "z "
-cw2 40 165 -min -10 -max 10 tranZ;
separator;
separator;
separator -style "double" -w 260;
separator;
separator;
button -l "Frame" -c sc_frameCount;
showWindow "sc_gui";
separator;
separator;
}
proc sc_getObj()
{
string $sel[] = (`ls -sl`);
string $firstObj = $sel[0];
textFieldButtonGrp -edit -text $firstObj selObj;
print $firstObj;
}
proc sc_frameCount()
{
int $start = (`textFieldGrp -query -text start`);
int $end = (`textFieldGrp -query -text finish`);
int $min = 1;
int $max = 10;
string $sel[] = (`select`);
string $Ty = "ty";
$currentFrame = $start;
for ($currentFrame > $start; $currentFrame < $end;)
{
int $randGen = rand($min,$max);
string $selObj = (`textFieldButtonGrp -query -text selObj`);
float $randMoveX = (`floatSliderGrp -query -value tranX`);
float $randMoveY = (`floatSliderGrp -query -value tranY`);
float $randMoveZ = (`floatSliderGrp -query -value tranZ`);
string $objAttrX = $selObj + ".translateX";
string $objAttrY = $selObj + ".translateY";
string $objAttrZ = $selObj + ".translateZ";
int $objAttrGetX = `getAttr $objAttrX`;
int $objAttrGetY = `getAttr $objAttrY`;
int $objAttrGetZ = `getAttr $objAttrZ`;
int $finalMoveX = ($objAttrGetX + $randMoveX);
int $finalMoveY = ($objAttrGetY + $randMoveY);
int $finalMoveZ = ($objAttrGetZ + $randMoveZ);
$currentFrame = ($currentFrame + $randGen);
currentTime -edit $currentFrame;
setAttr $objAttrX $finalMoveX;
setAttr $objAttrY $finalMoveY;
setAttr $objAttrZ $finalMoveZ;
print ($currentFrame + "\n");
print ($randMoveX + "\n");
print ($randMoveY + "\n");
print ($randMoveZ + "\n");
setKeyframe `textFieldButtonGrp -query -text selObj`;
}
}
sc_gui()