PDA

View Full Version : global variables Problem??? Please help.


Seemoo
03-17-2006, 07:10 PM
Hi everybody

I am trying to create a little script and I got stuck.

// STEP 1
// Creating a "DropDown" Menu with the optionMenu command,
// which lists all Cameras available in the scene.
string $cam[] = `ls -cameras`;
int $size = size($cam) ;

optionMenu -label "Camera" -cc SelChange Camera;
for($i=0;$i<$size;++$i) {
menuItem -label $cam[$i];
}

// STEP 2
// procedure SelChange gets called whenever I change the selection in the Camera
// optionMenu. It reads the new camera name into the global string $camName.

proc SelChange (){
global string $camName ;
$camName = `optionMenu -q -v Camera`;
}

// StEP 3
// I want to feed $camName back into a attrFieldSliderGrp (which is located outside the
// SelChange proc). But there $camName does not get updated from that procedure.... So It
// will keep changing the old selection from the DropDown Menu and not the new camera
// selected.

attrFieldSliderGrp -l "Zoom" -min 0.5 -max 10 -at ($camName + ".postScale") ;

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

Can anybody help me feed that new updated $camName (after it passed through the SelChange proc) back into the attrFieldSliderGrp?

Thank you very much for you help.

Simon

RyanT
03-17-2006, 08:37 PM
So the problem I think is when you create the window and tell it what attribute to be attached to it connects itself with that attribute. It is not dynamic. And you want something that is dynamic. Like comthing that uses a changeCommand and uses a function to figure out what it needs to change. This code below will do that for you.

You cant use the attrFieldSliderGrp though. Here is the code:


global string $camName;
string $cam[] = `ls -cameras`;
int $size = size($cam);
proc SelChange ()
{
global string $camName;
$camName = `optionMenu -q -v Camera`;
}
proc changeZoom ()
{
global string $camName;
float $getVal = `floatSlider -q -value zoomField`;
setAttr ($camName + ".postScale") $getVal zoomField;
}
string $window = `window`;
columnLayout;
optionMenu -label "Camera" -cc SelChange Camera;
for($i=0;$i<$size;++$i)
{
menuItem -label $cam[$i];
}
showWindow $window;
print ($camName + " is the name of your camera.\n");
floatSlider -min 0.5 -max 10 -cc ("changeZoom;") zoomField;



Also please note when posting check to see if your code works at least to the point it breaks. Just using the code you posted it didnt even create the window for the menu items to be created in. Dont worry about it, it wasnt a big deal but it might get you quicker responses in the future.

Have fun
-RyanT

Seemoo
03-17-2006, 08:53 PM
You rock!

Thanks a lot for your help. Sorry for not posing the whole code, I will do that in the future...

Just one more qustion:

Your slider doesn't update the viewport while sliding it (just after I let the slider thingy go). Which is probably because it is switching back and forth from procedure to procedure. Is there a way to keep it updating while sliding?

Thanks again

Simon


by the way, here is the code I had before:


string $Mag;
if (`window -exists $Mag`)
deleteUI $Mag ;
window -tlb on -width 180 -height 130 -title "Magnifier" $Mag ;
columnLayout -adjustableColumn true Base ;

string $cam[] = `ls -cameras`;
int $size = size($cam) ;

optionMenu -label "Camera" -cc SelChange Camera;
for($i=0;$i<$size;++$i) {
menuItem -label $cam[$i];
}

rowLayout -nc 3 -cw3 35 50 100 ;
button -w 35 -l "Zoom" -align "center" -c "setAttr ($camName +\".postScale\") 1";
attrFieldSliderGrp -hmb 1 -l "" -cw4 1 35 100 1 -min 0.5 -max 10 -pre 2 -at ($camName + ".postScale") -cc SelChange;

setParent .. ;
separator -st none -h 5 ;

rowLayout -nc 3 -cw3 35 50 100 ;
button -w 35 -l "LR" -align "center" -c "setAttr ($camName +\".filmTranslateH\") 0";
attrFieldSliderGrp -hmb 1 -l "" -cw4 1 35 100 1 -min -1 -max 1 -pre 2 -at ($camName + ".filmTranslateH") ;

setParent .. ;
separator -st none -h 5 ;

rowLayout -nc 3 -cw3 35 50 100 ;
button -w 35 -l "UD" -align "center" -c "setAttr ($camName+\".filmTranslateV\") 0";
attrFieldSliderGrp -hmb 1 -l "" -cw4 1 35 100 1 -min -1 -max 1 -pre 2 -at ($camName + ".filmTranslateV") ;
showWindow $Mag ;
print (`optionMenu -q -v Camera` + " END \n") ;

proc SelChange (){
global string $camName ;
$camName = `optionMenu -q -v Camera`;
print ($camName + " END SelChange \n");
}

RyanT
03-17-2006, 09:21 PM
Change this line:

floatSlider -min 0.5 -max 10 -cc ("changeZoom;") zoomField;

to:

floatSlider -min 0.5 -max 10 -dc ("changeZoom;") zoomField;

That uses the drag Command instead which means it executes constantly when you drag. If you ever wonder if there is another argument you can try "help floatSlider" or "help whatever" and it will show you all the possible arguments in your command line. The mel command reference is my good friend too.

-RyanT

Seemoo
03-17-2006, 09:24 PM
Great!!!

Thanks again! :-)


Simon

CGTalk Moderation
03-17-2006, 09:24 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.