PDA

View Full Version : Pause/Resume a script?


jgibz
04-24-2006, 07:32 PM
Hi everyone,

I've been working on this script for setting up a character rig. At one point a new window is created within a procedure which requires the use of a string variable declared within the same procedure. The problem is, the window pops up and the procedure keeps running, as it's called by a button command from the original script UI. So the string the window needs not only no longer exists by the time the user interacts with the new window, but the changes the new pop-up window is supposed to make are obsolete, as it is supposed to effect objects before the procedure finishes.

So is there a way to pause a preocedure, or stop it from evaluating until the pop-up window is closed?

an example... global proc test()
{
string $neededString = "needed";
float $neededFloat;

string $newWindow = `window -title "window1"`;
columnLayout;
floatSliderGrp -label "size"
-field true
-value 0
-minValue -10 -maxValue 10
rowLayout;
button -label "scale now" -command "$neededFloat = `floatSliderGrp -q -value myWin`; setAttr ($needeString + \".scale\") $neededFloat $neededFloat $neededFloat" myWin;


showWindow $newWindow;

}

clicking the button results in...
// Error: $neededFloat = `floatSliderGrp -q -value myWin`; setAttr ($needeString + ".scale") $neededFloat $neededFloat $neededFloat; //
// Error: "$needeString" is an undeclared variable. //


does anyone know how to fix this?

goleafsgo
04-24-2006, 08:54 PM
You should probably add a callback to your UI slider and then in the callback do whatever you need to do. But, no...the string you are declaring is local to the proc so what you have isn't going to work.

Looking at what you have there I think the attrFieldSliderGrp might be a control that you could use...try this example:


window -title "Attr Field Slider Groups";
string $objName[] = `sphere`;
columnLayout;
attrFieldSliderGrp -min -10.0 -max 10.0 -at ($objName[0]+".tx");
showWindow;

jgibz
04-24-2006, 11:50 PM
Thanks for the info,

How would I go about creating a callback?

isoparmB
04-25-2006, 01:18 PM
I think this is an issue regarding variable scope. In your example, since $neededString is declared within the bloc of a procedure, it exists only within the scope of that proc. If you turn your proc into one that returns a string value, however, and input the return value into a variable which exists outside your proc, I think you will get what you're looking for. Here is a modified example:

global proc string test()
{
string $neededString = "needed";
float $neededFloat;

string $newWindow = `window -title "window1"`;
columnLayout;
floatSliderGrp -label "size"
-field true
-value 0
-minValue -10 -maxValue 10
rowLayout;
button -label "scale now" -command "$neededFloat = `floatSliderGrp -q -value myWin`; setAttr ($neededString + \".scale\") $neededFloat $neededFloat $neededFloat" myWin;


showWindow $newWindow;
return $neededString;
};

float $neededFloat;
string $neededString;
$neededString = test();

CGTalk Moderation
04-25-2006, 01:18 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.