I need to query the type of a variables i read in from optionVars.
How do i know i deal with an integer or string?
This must be easy but i dont get it.

Less important: is there a way to show a progress bar in mel?

alexnardini

06-27-2007, 09:24 PM

Suppose to have declared those variables:

int $tmp = 100;
float $tmp2 = 200;
vector $tmp3 = <<300, 300, 300>>;

If you whant to know the type of those variables after their creation, you can use the command "whatIs".

whatIs "$tmp";
// Result: int variable //

whatIs "$tmp2";
// Result: float variable //

whatIs "$tmp3";
// Result: vector variable //

For the variables inside the optionVar, you can do as follow;

Build your 'command' as a "string" and query the optionVar variable you need:

string $cmd = "optionVar -q \"CEPrecision\"";

then, 'eval' your string in this way:

$cmdEval = eval($cmd);

and finally use `whatIs` to know the type of the variable coming from the `eval` command:

whatIs "$cmdEval";
// Result: int variable //

katisss

06-27-2007, 09:25 PM

thanks so much, i was just about to give up on this.

katisss

06-28-2007, 08:40 AM

That's completely cool with int or strings
but how do i find out if its array or a single value?
Its even hard to query an optionvar without knowing.
There is the arraysize flag but it also works for single vlaue vars.

i tried to do it in a for loop yesterday and what
seems to happen is it seems to remember the data type of $cmdArrayEval
had in the previous iteration. So if the first value is an int there is a type error
if the next value is a string.... Maybe i am wrong.
I am doing an OptionVar to Xml script (and back), so i dont know the data types of th eoptionVars created by the user.

alexnardini

06-28-2007, 10:41 AM

If you tried my example code in the ScriptEditor without enclose it
within the braces, obviously it will remember the value as $cmdArrayEval
will become a Global variable and will exist until you d' nt close and re-open Maya.

Follow Us On:

The CGSociety

The CGSociety is the most respected and accessible global organization for creative digital artists. The CGS supports artists at every level by offering a range of services to connect, inform, educate and promote digital artists worldwide. More about us