Toggle Scripts question


#1

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;
    [size=1][/size]
    [size=1][size=2]B. Display preference (Show wire or not)[/size][/size]
    [size=1][size=2][/size][/size]
    [size=1][size=2]1. [size=1]displayPref -wsa “full”;
    [/size][/size][/size][size=1][size=2]2. [size=1]displayPref -wsa “none”;[/size][/size][/size]
    [size=1][size=2][size=1][/size][/size][/size]
    [size=1][size=2][size=1][size=2][/size][/size][/size][/size]
    [size=1][size=2][size=1][size=2]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[/size][/size][/size][/size]
    [size=1][size=2][size=1][size=2][/size][/size][/size][/size]
    [size=1][size=2][size=1][size=2]There are dozens of toggle scripts, but there is always more left to do :slight_smile:
    [/size][/size][/size][/size]

#2

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";

#3

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?


#4

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.


#5

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.