PDA

View Full Version : Boolean variables


DezFX
01-15-2004, 01:22 AM
If I want to querry the boolean value (1,0) of the grid, what kind of variable set do I need to define? Below is a script I'm working on to toggle the grid on and off depending on which viewport is active.

------------
int $vis; ///this is where I need help. Is it an int variable that I need to declare for a boolean?
{
// get active panel
string $currentPanel = `getPanel -underPointer`;

// no panel under pointer --> get panel with focus
if ($currentPanel == "")
$currentPanel = `getPanel -withFocus`;

// get panel display type
string $panelType = `getPanel -typeOf $currentPanel`;

// get panel name
string $currentName = `modelPanel -query -label $currentPanel`;

if ($panelType == "modelPanel")
{
// Toggle grid in correct panel:
if($currentName == "Top View")
{$vis = '-q -grid modelPanel1'; ///I am getting a syntax error here.
if ($vis == "0")
modelEditor -e -grid 1 modelPanel1;
if ($vis == "1")
modelEditor -e -grid 0 modelPanel1;
}

if($currentName == "Side View")
{$vis = '-q -grid modelPanel2'; ///I am getting a syntax error here.
if ($vis == "0")
modelEditor -e -grid 1 modelPanel2;
if ($vis == "1")
modelEditor -e -grid 0 modelPanel2;
}

if($currentName == "Front View")
{$vis = '-q -grid modelPanel3'; ///I am getting a syntax error here.
if ($vis == "0")
modelEditor -e -grid 1 modelPanel3;
if ($vis == "1")
modelEditor -e -grid 0 modelPanel3;
}

if($currentName == "Persp View")
{$vis = '-q -grid modelPanel4'; ///I am getting a syntax error here.
if ($vis == "0")
modelEditor -e -grid 1 modelPanel4;
if ($vis == "1")
modelEditor -e -grid 0 modelPanel4;
}
}
}
------------

macaroniKazoo
01-15-2004, 02:34 AM
you'll want to use: $vis = `modelEditor -q -grid modelPanel1';

and yes, booleans are just int variables. incidentally, any int greater than 0 evaluates as true.

so if you run this:
int $isItOn = 5;
if( $isItOn ) print "yes, I'm on!\n";

you will see the message printed to the script editor. its kinda useful for things like testing whether an array is empty or not. ie:

string $array[] = { "yeah", "no" };
if( `size $array` ) print "this is not an empty array\n";

again u will get a message printed to the script editor.

just FYI. :)

DezFX
01-15-2004, 08:02 AM
Thanks for the help. I placed the syntax into my script as you suggested and received the following error when executing:

*******************
// Error: {$vis = 'modelEditor -q -grid modelPanel1';
//
// Error: Line 20.10: Syntax error //
// Error: {$vis = 'modelEditor -q -grid modelPanel2';
//
// Error: Line 28.10: Syntax error //
// Error: {$vis = 'modelEditor -q -grid modelPanel3';
//
// Error: Line 36.10: Syntax error //
// Error: {$vis = 'modelEditor -q -grid modelPanel4';
//
// Error: Line 44.10: Syntax error //
*******************

Any ideas?

macaroniKazoo
01-15-2004, 09:09 PM
i can't see a syntax error on that line, but perhaps you're getting one on the next line with:

if ($vis == "0")

the quotes there mean that the zero is handled as a string, not an int. i personally would use the much simpler syntax:

{
$vis = 'modelEditor -q -grid modelPanel1';

if( $vis ) so something;
else another thing;
...

but if that doesn't work, i'm really not too sure. i can't see anything wrong with it.

zachgrachan
01-15-2004, 09:20 PM
hey, that's a long script for that... I use this bit of code for all kinds of modelEditor toggles, from object type isolation to toggling the grid, xray, wire on shaded and all kinds of other stuff (a shelf and a marking menu full of 'em!)


//finds panel with current focus
string $panel = `getPanel -wf`;

//toggles the boolean value
if(`modelEditor -q -grid $panel` == 0)
modelEditor -e -grid 1 $panel;
else
modelEditor -e -grid 0 $panel;


If you want to use it for something else, just turn on "echo all commands" in the script editor and use the interface to toggle it. Then replace -grid with whatever prints out.

Incidentally, the problem you are having when using :

$vis = '-q -grid modelPanel1'

is that you are leaving out the actual command - modelEditor...

$vis = 'modelEditor -q -grid modelPanel1'


Also, I don't think there's any reason to check for top, front, persp or side; just use the variable you saved the name of the current panel in:

string $currentName = `modelPanel -query -label $currentPanel`;

DezFX
01-15-2004, 09:43 PM
Thanks for the help guys, I'm very new (second script) and just learning. I did learn there is a typo in my syntax resulting in an error. I was using the ' key instead of the ` key. I also learned that my script was way too long and complicated. I've received input from other forums helping me to learn how I could have written this in a simpler method as well.

zachgrachan: I'll also take your advice and make a shelf button with sample script to use in future programs. I've got a few so far, and really like this style of programming.

Simpler method:
{

string $currentPanel = `getPanel -underPointer`;


if ($currentPanel == "")

$currentPanel = `getPanel -withFocus`;



if(`modelEditor -q -exists $currentPanel`){

if(`modelEditor -q -grid $currentPanel`)

modelEditor -e -grid 0 $currentPanel;

else

modelEditor -e -grid 1 $currentPanel;

}

}

:beer:

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