View Full Version : Toggle Scripts question


Haider of Sweden
05 May 2005, 04:42 PM
I got two question, concerning toggles

Toggles are great, but how shall they be coded?
I got two icons for each function

A. Click Drag

1. selectPref -clickDrag true;
2. selectPref -clickDrag false;

B. Display preference (Show wire or not)

1. displayPref -wsa "full";
2. displayPref -wsa "none";


it would be great if someone could tell how to make a toggle, so that one click can result in either A1/A2 or B1/B2

There are dozens of toggle scripts, but there is always more left to do :-)

DezFX
05 May 2005, 05:22 PM
Instead of explicitly setting with two buttons, set the value to be "NOT" what it currently is.
selectPref -clickDrag (!`selectPref -q -clickDrag`);

The second one is more to it because you have to query a string value to drive the toggle.
string $wsa = `displayPref -q -wsa`;
if ($wsa == "full")
displayPref -wsa "none";
else
displayPref -wsa "full";

Haider of Sweden
05 May 2005, 06:40 AM
So, does the -q exist in most commands?

And, if we're talking about a 1/0 issue, the first solution ("not"-method) would work best and easyest?

DezFX
05 May 2005, 09:48 AM
Most commands work in 3 modes; query (-q), edit (-e), and create (-c). By default most commands are in create mode so the -c flag is not necessary. You can refer to the Maya docs to verify which modes exist for which commands.

Yes, the easiest way to toggle a boolean is to query the current value and use the NOT (!) operator to set the value to it's opposite.

The reason for the if/else statement in the second toggle is because the return value of the query call is a string (none or full) that you need to test and then assign the new value.

CGTalk Moderation
05 May 2005, 09:48 AM
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.


1