Reputation: 2703
I'm new to mel script. I know that I can toggle manually xray with the code.
displaySurface -xRay true; //Xray on
displaySurface -xRay false; //Xray off
But I want it to toggle automatically, like
if(xRay on)
set xRay off
else
set xRay on
I know that I can check xRay on or off with the command
displaySurface -query -xRay;
But I just can't put this command into if block
. I tried many things like the code below, but nothing works.
if(`displaySurface -query -xRay` == 1) // Error: line 1: Cannot use data of type int[] in a scalar operation. //
print("To be or not to be");
Upvotes: 0
Views: 2194
Reputation: 497
The brackets after int
in the error Cannot use data of type int[]
indicates that the function returns an integer array. So you need to take the first element [0]
of the array.
$xRayOnArray = `displaySurface -q -xRay`;
if ($xRayOnArray[0] == 0) {
print("X-Ray is enabled");
} else {
print("X-Ray is disabled");
}
Why it returns an array is a puzzle. It isn't documented and the function can only query a single object at a time.
Upvotes: 0
Reputation: 54
Looks like displaySurface -query -xRay
is returning an array. This worked for me:
int $y[] = `displaySurface -query -xRay`;
if( $y[0] == 1)
print("To be or not to be");
Upvotes: 0