How to pass eval result to variable

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 06 June 2013   #1
How to pass eval result to variable

Hi,
I'm not mel scripting all the time, so I got stuck with something which might be simple problem.

  $hexbroj="#0b003c";
  string $prvi = "0x"  + `substring $hexbroj 2 3`;
  string $drugi = "0x" + `substring $hexbroj 4 5`;
  string $treci = "0x" + `substring $hexbroj 6 7`;
  string $rgbz = `evalEcho ("print " + $treci)`;
  

the result of eval command doesn't go into string. I've tried array too, result is empty as well.
Any pointer?

Thanks


Als
__________________
"No Bucks, NO Buck Rogers!"

VFX rule no. 387
# Just redo it!

 
Old 06 June 2013   #2
I think it is because "print" does not return anything, so in this case, neither does eval.
If you were running a function with a return value it would go into your variable, and you would need to match the type of variable with the type being returned.

David
__________________
http://www.djx.com.au
 
Old 06 June 2013   #3
Code returns the value, which is a way to convert hexadecimal number to decimal.
In this case 60.
It prints 60, but the value doesn't go into the variable.
I'm not sure if the value goes from string to int or whatever, but it does print.
(try code if you like)

How could I do it with function ?

Thanks for your reply


Als
__________________
"No Bucks, NO Buck Rogers!"

VFX rule no. 387
# Just redo it!

 
Old 06 June 2013   #4
Yes, print dumps it in the script editor, but the print function does not return a value.
The only solution I could think of was to cheat and use a little bit of python.

$hexbroj="#0b003c";
string $treci = "0x" + `substring $hexbroj 6 7`;
string $rgbz = python("int('"+$treci+"',16)");
print $rgbz;


David
__________________
http://www.djx.com.au
 
Old 06 June 2013   #5
Hi David,

This seems to me an error internally in maya if it doesn't do this.
But luckily there is python!
Thanks so much!!!


Als
__________________
"No Bucks, NO Buck Rogers!"

VFX rule no. 387
# Just redo it!

 
Old 07 July 2013   #6
It's definitely not an error, print is a void, it's an enactor, not something supposed to return a value.

The problem is you are already setting something, then using it to print, and then wanting it back from that. It's a rather pointless approach to be honest.

Set rgbz to be equal to the whatever type casting of treci you wish it to be and print rgbz instead and you won't have the problem.

Print does what it says on the can, even if it returned what you wished it to return it'd be a pretty dysfunctional way to alter data.
Your data handling should be clear, explicit, and decoupled from logging it.
__________________
Come, Join the Cult http://www.cultofrig.com - Rigging from First Principles
 
Old 07 July 2013   #7
Hi Raffaele,

This was simple quick way for me to convert hexadecimal number into decimal, that's all.

int $paja = 0x3c;

 print $paja;

 60


int $paja = $treci; // Warning: line 1: Converting string "0x3c" to an int value of 0.


I was trying to solve this through print. Seemed fastest way.
What is better way to do this and avoid that error ?

I used to do a lot of shell and that was quite fast way of doing things through echo command.
I'm not full time programmer.

Thanks for taking interest


Als
__________________
"No Bucks, NO Buck Rogers!"

VFX rule no. 387
# Just redo it!

 
Old 07 July 2013   #8
Hex numbers are purely notational, internally they are stored as integers.
0x simply tells maya that the following chunk will be in hex notation, but internally it's always of type int.
IE:

    print 0x23;
    

Will print 35.

You can store as strings, and then feed them to an eval to cast to int (assuming you are doing something wonky like parsing html feeds and needing the decimal values)

    string $sHexVar = "0x23";
    eval("int $siHexVar =" + $sHexVar);
    print $siHexVar;
    


So, you DO NOT need to convert them you can write them like that right away.
They will be integers right away. They are, however, NOT floats, so if you need to operate on "decimals" you might need to cast the int to a float afterwards.

Casting in MEL is implicit in cross-assignment, like this:

 int $siHex = 0x23;
 float $flHex = $siHex;
 
__________________
Come, Join the Cult http://www.cultofrig.com - Rigging from First Principles

Last edited by ThE_JacO : 07 July 2013 at 06:20 AM.
 
Old 07 July 2013   #9
I really tried that with eval, but it didn't work.
It must be that I was wrong somewhere with syntax.
I'm trying to make a mel to read a pallete from gimp, which is hexadecimal,
then make color ramp for colors for nparticles, and later who knows what else.

Thank you for help


Al

Originally Posted by ThE_JacO: Hex numbers are purely notational, internally they are stored as integers.
0x simply tells maya that the following chunk will be in hex notation, but internally it's always of type int.
IE:

     print 0x23;
     

Will print 35.

You can store as strings, and then feed them to an eval to cast to int (assuming you are doing something wonky like parsing html feeds and needing the decimal values)

     string $sHexVar = "0x23";
     eval("int $siHexVar =" + $sHexVar);
     print $siHexVar;
     


So, you DO NOT need to convert them you can write them like that right away.
They will be integers right away. They are, however, NOT floats, so if you need to operate on "decimals" you might need to cast the int to a float afterwards.

Casting in MEL is implicit in cross-assignment, like this:

  int $siHex = 0x23;
  float $flHex = $siHex;
  
__________________
"No Bucks, NO Buck Rogers!"

VFX rule no. 387
# Just redo it!

 
Old 07 July 2013   #10
Thread automatically closed

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.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 12:45 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.