PDA

View Full Version : multiple orient constraints


zachgrachan
04-11-2003, 06:00 PM
Hey all,

I am trying to write what seemed like it would be a simple script, but I am completely stuck. It's telling me that the object: " " can't be found....

Anybody got any ideas? thanks in advance.


/*

proc to do it lots of times

passed: string $a

this is the text from the textField, name of

the target

performs: performOrientConstraint

orient constrains multiple objects to one

target

returns: none

*/

global proc zgOrientMany (string $target)

{

string $sel [] = `ls -sl`;

string $current;

for ($current in $sel)

{

select -r $current;

select -tgl $target;

performOrientConstraint 0;

orientConstraint -w 1;

}

}





/*

A GUI to make life easier

passed: none

performs: GUI window to run zgOrientMany

returns: none

*/

global proc zgGUI ()

{

string $textfield = "objects";

global string $target = " ";

window -t "Some scripts";

columnLayout;

text -l " Orient mulitle objects to a single target ";

text -l " 1. First select all the objects to constrain: ";

text -l " 2. Then type in the name of the target: ";

textField -w 300 $textfield;

textField -q -tx $target;

button -w 300 -l " 3. Then Click this button."

-c "zgOrientMany $target";

setParent..;

showWindow;

}

//written by zach grachan

//email: webmaster@zgrachan.com

bigfatMELon
04-12-2003, 05:07 AM
The problem is that $target = "" and as this is written it will always = "".

You need to change your button command so that either it or the proc that it calls querries the field for the current value.

1) Querrying the field for the value before building the button does nothing because the field is empty at that point. That window hasn't even drawn yet!

2) And even if there were a value in the field, the $target variable exists within the UI proc's scope, while the button command exists within it's the general scope. Therefore, the value of $target will always be "".

Do this instead. Change your text field call to:

textField -w 300 "zgTargetField";

This gives the field a unique name by which it can be querried later. Yes, you did this, but I'm going with an explicitly unique name here.

Now forget about doing anything else with the field in the UI portion. Instead of trying to pass this info to your OrientMany proc, querry the field from within that proc.

$target = `textField -q -tx "zgTargetField"`;

Also, you might consider a UI that doesn't require typing at all by adding a button to the UI that will load the text field with the name of any selected object. Artist hate typing... well, most do.

-jl

CGTalk Moderation
01-14-2006, 09:00 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.