PDA

View Full Version : Receive value from check box. how?


Pherx
03-25-2006, 10:24 AM
I'm a total nub when it comes to mel scripting, all i've been taught is how to hack one together... and well that's exactly where i started on this script. I grabbed one from some misc site, modified it to do the stuff i wanted it to do and now i want to modify it even more. Originally teh script just randomly moved junk around the scene, i've added some additional UI elements, and the ability to use rotation and scaling aswell. What i want to do is add a checkbox in the UI to turn off certain aspects of teh script (mainly the scaling.) anything with qc before it is whoever's mel script this originally was (i think it was originally russian) anything with mike or m before it is my n00b code.



global proc mikerandomObjects(){
if ( `window -exists mikerandomObjects_ui` == true )
deleteUI mikerandomObjects_ui;
int $colWidth=120;

window -maximizeButton false -resizeToFitChildren true -menuBar true -menuBarVisible true -title "Randomize Objects Rotation Translation Scale" mikerandomObjects_ui;

menu -label "Edit" -tearOff false;
menuItem -label "Reset Settings" -c "qcoesRandom";
menu -label "Help" -tearOff false;
menuItem -label "Help With Randomize Objects" -c "qcoepom 1";
menuItem -divider true;
menuItem -label "Script Information" -c "qcoepom 2";

///framesy
columnLayout -adjustableColumn true -rowSpacing 6;

frameLayout
-label "Randomize Settings"
-labelAlign "center"
-cll true
-lw 130
-mh 3
//-cc "ct_adjustUI 0"
//-ec "ct_adjustUI 0"
-bs "etchedIn"
-bv true
qcoe_ramka;


columnLayout -adjustableColumn true;
rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Rotate X Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_xtolerance;
setParent ..;
separator -h 5;

rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Rotate Y Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_ytolerance;
setParent ..;
separator -h 5;

rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Rotate Z Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_ztolerance;
setParent ..;
separator -h 5;


rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Translate X Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_translatextolerance;
setParent ..;
separator -h 5;

rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Translate Y Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_translateytolerance;
setParent ..;
separator -h 5;
rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Translate Z Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_translateztolerance;
setParent ..;
separator -h 5;
//Mike Edit for Scaling
checkBox -label "Scale" -align "left" -v false scaleCheckBox;

rowLayout

-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Scale X Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 1
-minValue 0
-maxValue 5
mike_scalextolerance;
setParent ..;
separator -h 5;

rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Scale Y Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 1
-minValue 0
-maxValue 5
mike_scaleytolerance;
setParent ..;
separator -h 5;
rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Scale Z Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 1
-minValue 0
-maxValue 5
mike_scaleztolerance;
setParent ..;
separator -h 5;


showWindow mikerandomObjects_ui;

string $qcoe_button = `button
-label "Randomize selected objects"
-command "qcoesrandom"
qcoesrandombutton`;

}
proc qcoesrandom(){


///deklaracja zmiennych
string $objList[];

///pobranie listy
$objList = `selectedNodes`;

//wielkosc listy
int $listSize=size($objList);
float $randxtolerance=`floatSliderGrp -q -value qcoe_xtolerance`;
float $randytolerance=`floatSliderGrp -q -value qcoe_ytolerance`;
float $randztolerance=`floatSliderGrp -q -value qcoe_ztolerance`;
float $mrandxtolerance=$randxtolerance*-1;
float $mrandytolerance=$randytolerance*-1;
float $mrandztolerance=$randztolerance*-1;
//petla glowna
float $randtranslatextolerance=`floatSliderGrp -q -value qcoe_translatextolerance`;
float $randtranslateytolerance=`floatSliderGrp -q -value qcoe_translateytolerance`;
float $randtranslateztolerance=`floatSliderGrp -q -value qcoe_translateztolerance`;
float $mrandtranslatextolerance=$randtranslatextolerance*-1;
float $mrandtranslateytolerance=$randtranslateytolerance*-1;
float $mrandtranslateztolerance=$randtranslateztolerance*-1;

//Scale

float $randscalextolerance=`floatSliderGrp -q -value mike_scalextolerance`;
float $randscaleytolerance=`floatSliderGrp -q -value mike_scaleytolerance`;
float $randscaleztolerance=`floatSliderGrp -q -value mike_scaleztolerance`;
float $mrandscalextolerance=$randscalextolerance*1.1;
float $mrandscaleytolerance=$randscaleytolerance*1.1;
float $mrandscaleztolerance=$randscaleztolerance*1.1;
for ($count = 0; $count < $listSize; $count++)



{


rotate -r -ws `rand $mrandxtolerance $randxtolerance` `rand $mrandytolerance $randytolerance` `rand $mrandztolerance $randztolerance` $objList[$count];
move -r `rand $mrandtranslatextolerance $randtranslatextolerance` `rand $mrandtranslateytolerance $randtranslateytolerance` `rand $mrandtranslateztolerance $randtranslateztolerance` $objList[$count];
scale -r `rand $mrandscalextolerance $randscalextolerance` `rand $mrandscaleytolerance $randscaleytolerance` `rand $mrandscaleztolerance $randscaleztolerance` $objList[$count];

}


}


Any help would be great, thanks in advance.

Segmoria
03-25-2006, 02:27 PM
Ok to do that you have to give IDs to your text and floatSliderGrp objects, then query the checkbox value and using an if statement you either enable the status of those objects or disable it. The same also goes to check whether you should apply the scale transformation.

I made some adjustments in the part where you create the scale attributes UI objects and I added a procedure at the end, so here it is:

global proc mikerandomObjects(){
if ( `window -exists mikerandomObjects_ui` == true )
deleteUI mikerandomObjects_ui;
int $colWidth=120;

window -maximizeButton false -resizeToFitChildren true -menuBar true -menuBarVisible true -title "Randomize Objects Rotation Translation Scale" mikerandomObjects_ui;

menu -label "Edit" -tearOff false;
menuItem -label "Reset Settings" -c "qcoesRandom";
menu -label "Help" -tearOff false;
menuItem -label "Help With Randomize Objects" -c "qcoepom 1";
menuItem -divider true;
menuItem -label "Script Information" -c "qcoepom 2";

///framesy
columnLayout -adjustableColumn true -rowSpacing 6;

frameLayout
-label "Randomize Settings"
-labelAlign "center"
-cll true
-lw 130
-mh 3
//-cc "ct_adjustUI 0"
//-ec "ct_adjustUI 0"
-bs "etchedIn"
-bv true
qcoe_ramka;


columnLayout -adjustableColumn true;
rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Rotate X Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_xtolerance;
setParent ..;
separator -h 5;

rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Rotate Y Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_ytolerance;
setParent ..;
separator -h 5;

rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Rotate Z Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_ztolerance;
setParent ..;
separator -h 5;


rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Translate X Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_translatextolerance;
setParent ..;
separator -h 5;

rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Translate Y Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_translateytolerance;
setParent ..;
separator -h 5;
rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Translate Z Tolerance";
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 0
-minValue 0
-maxValue 50
qcoe_translateztolerance;
setParent ..;
separator -h 5;
//Mike Edit for Scaling
checkBox -label "Scale" -align "left" -v true -cc "changeScaleUI" scaleCheckBox;

rowLayout

-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;

text -l "Scale X Tolerance" mike_textscalextolerance;

floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 1
-minValue 0
-maxValue 5
mike_scalextolerance;

setParent ..;
separator -h 5;

rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Scale Y Tolerance" mike_textscaleytolerance;
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 1
-minValue 0
-maxValue 5
mike_scaleytolerance;
setParent ..;
separator -h 5;
rowLayout
-numberOfColumns 4
-cat 1 "left" 5
-columnWidth 1 $colWidth
-columnWidth 2 30;
text -l "Scale Z Tolerance" mike_textscaleztolerance;
floatSliderGrp
-field true
-precision 2
-sliderStep .1
-value 1
-minValue 0
-maxValue 5
mike_scaleztolerance;
setParent ..;
separator -h 5;


showWindow mikerandomObjects_ui;

string $qcoe_button = `button
-label "Randomize selected objects"
-command "qcoesrandom"
qcoesrandombutton`;

}


proc qcoesrandom(){


///deklaracja zmiennych
string $objList[];

///pobranie listy
$objList = `selectedNodes`;

//wielkosc listy
int $listSize=size($objList);
float $randxtolerance=`floatSliderGrp -q -value qcoe_xtolerance`;
float $randytolerance=`floatSliderGrp -q -value qcoe_ytolerance`;
float $randztolerance=`floatSliderGrp -q -value qcoe_ztolerance`;
float $mrandxtolerance=$randxtolerance*-1;
float $mrandytolerance=$randytolerance*-1;
float $mrandztolerance=$randztolerance*-1;
//petla glowna
float $randtranslatextolerance=`floatSliderGrp -q -value qcoe_translatextolerance`;
float $randtranslateytolerance=`floatSliderGrp -q -value qcoe_translateytolerance`;
float $randtranslateztolerance=`floatSliderGrp -q -value qcoe_translateztolerance`;
float $mrandtranslatextolerance=$randtranslatextolerance *-1;
float $mrandtranslateytolerance=$randtranslateytolerance *-1;
float $mrandtranslateztolerance=$randtranslateztolerance *-1;

//Scale

float $randscalextolerance=`floatSliderGrp -q -value mike_scalextolerance`;
float $randscaleytolerance=`floatSliderGrp -q -value mike_scaleytolerance`;
float $randscaleztolerance=`floatSliderGrp -q -value mike_scaleztolerance`;
float $mrandscalextolerance=$randscalextolerance*1.1;
float $mrandscaleytolerance=$randscaleytolerance*1.1;
float $mrandscaleztolerance=$randscaleztolerance*1.1;
for ($count = 0; $count < $listSize; $count++)



{


rotate -r -ws `rand $mrandxtolerance $randxtolerance` `rand $mrandytolerance $randytolerance` `rand $mrandztolerance $randztolerance` $objList[$count];
move -r `rand $mrandtranslatextolerance $randtranslatextolerance` `rand $mrandtranslateytolerance $randtranslateytolerance` `rand $mrandtranslateztolerance $randtranslateztolerance` $objList[$count];


int $status = `checkBox -q -value scaleCheckBox`;
if ($status == 1)
{
scale -r `rand $mrandscalextolerance $randscalextolerance` `rand $mrandscaleytolerance $randscaleytolerance` `rand $mrandscaleztolerance $randscaleztolerance` $objList[$count];
}


}


}

proc changeScaleUI()
{

int $status = `checkBox -q -value scaleCheckBox`;

if ($status == 1)
{
floatSliderGrp -e -enable 1 mike_scalextolerance;
floatSliderGrp -e -enable 1 mike_scaleytolerance;
floatSliderGrp -e -enable 1 mike_scaleztolerance;
text -e -enable 1 mike_textscalextolerance;
text -e -enable 1 mike_textscaleytolerance;
text -e -enable 1 mike_textscaleztolerance;

}

if ($status == 0)
{
floatSliderGrp -e -enable 0 mike_scalextolerance;
floatSliderGrp -e -enable 0 mike_scaleytolerance;
floatSliderGrp -e -enable 0 mike_scaleztolerance;
text -e -enable 0 mike_textscalextolerance;
text -e -enable 0 mike_textscaleytolerance;
text -e -enable 0 mike_textscaleztolerance;

}

}

mikerandomObjects();

Just have a look at the last proc that i added so you can understand how to query and edit UI objects.

Pherx
03-25-2006, 09:42 PM
Thank you very much Segmoria! that did exactly what i wanted :)

CGTalk Moderation
03-25-2006, 09:43 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.