Here's a hint to make things that toggle into really simple code:
toggleCmd -flag (1-`toggleCmd -q -flag`);
So in your case:
selectPref -useDepth (1-`selectPref -q -useDepth`);
To make it callable from the command line, you need to make it a global procedure and load it. Making it a procedure is simple:
global proc YourProcName()
{
code here
}
Usually you can put it in a .mel file, and source that file. That file can contain many procedures,. Say you put it in myStuff.mel (bad name, but you get the idea) - then you would load the script by:
source myStuff.mel;
Now you can call your proc when you need. If you want - combine those two into a single command, and map it toa hotkey or shelf item.
source myStuff.mel;YourProcName;
Re-sourcing it isn't slow so no worries there. As a bonus, if you have a single proc inside a script, and it's named the same as the file - calling it directly works. So if you have a myDoStuff procedure inside a myDoStuff .mel file, calling myDoStuff will auto-source it and run the proc in one step.
I have a large script for toggling many things since it's so common, I have a "CRtoggleStuff" command, and it takes an argument of what to toggle, and I just hard-code several of them in there. Something like this, off the top of my head:
Code:
global proc CRtoggleStuff (string $ mode )
{
if ($ mode=="cameraSelect")
selectPref -useDepth (1-`selectPref -q -useDepth`);
else if ($ mode=="thingy")
thingy -foo (1-`thingy-q -foo`);
else
error ("Unknown mode n");
}
Works great, and I can put complex switches in there, for things that cycle through 3 or more, or commands that are difficult to toggle. Keeps them all in one nice place.
Not sure why the code tags eat some stuff - I lost the $variable stuff in mine unless I separated the $ and the name and the \n I had to put a space in as well. So take that space out
