Home Coding, Scripting, Shaders

[Mel][Maya] Begginer. Is it possible to convert string text back to variable name?

Hey there. Begginer question. Is it possible in MEL to convert string text back to variable name. Here is rough example: $x=smoothstep(0,30,frame); $y=smoothstep(50,60,frame); $a=$x*$y; //down the script i have this: string $a="$x*$y"; Can i convert it back from string variable to $a=$x*$y; consisting corresponding values ?

Replies

  • poopipe
    Offline / Send Message
    poopipe grand marshal polycounter
    I don't do Mel but You should be able to use eval() to execute a string as if it were code
  • ll_k
    Thank you. It works of some kind, but not exactly as it needs to for me. It executes proper values but, unfortunately, without fades("smoothstep"). Perhaps it can be solved from another end. I'll try to explain.

    In general I have for loop for queried keyframes. After that i have to multiply every array item from this loop to each other.The only way i know of to do so is to make another for loop and then "stringArrayToString" to get desire result:
    float $xTmp[] = {}; 
    for( $i=0; $i<size($List); $i++ ){
    $xTmp[$i] = $x[$i];
    }
    $a = stringArrayToString($xTmp,"*");
    So i got this:
    string $a="$x[0]*$x[1]*$x[2]*$x[3]";
    But now i have to convert it back to variables values. And it seems doesn't work.
    So what Is another way may be in this case to multiply every item of array to each other?
Sign In or Register to comment.