Home Technical Talk

Connect attributes with condition statements in maya/mel?

polycounter lvl 5
Offline / Send Message
Jarmade polycounter lvl 5
I know you can directly connect two attributes with the connection editor or mel script, but what I can't figure out is how to connect them with some condition/expression which is evaluated each time the attributes are changed

i have one attribute that is in degrees rotation and i want to connect it to another attribute which is in radians rotation, so i need a way to evaluate a script to convert the values.

I could do this in 3ds max by wiring parameters and it let you type some maxscript to be evalated for the returned value.

Replies

  • Denny
    Options
    Offline / Send Message
    Denny polycounter lvl 14
    There are two ways. Either use Hypershade to use MultiplyDivide nodes to do the conversion (which is really fast, values are restricted to three decimals though so you loose precision).


    The other way is using an expression. Expressions can slow down your scene if you're not careful. A simple deg/rad-conversion shouldn't be a problem though.


    In the channelbox, select an attribute and go to the edit menu > expressions. Add for example:

    pCube1.rotateX = pCube2.rotateX*3.14159265358979/180;

    This will take the value from pCube2.rotateX and convert it to radians. The other way is creating the expression via MEL-script. In the MEL window do the following;
    // Create a toRadians procedure
    global proc int toRadians(float $value){
        return $value*3.14159265358979/180;
    }
    
    // Create expression on pCube1.rotateX
    expression -s "pCube1.rotateX = toRadians(pCube2.rotateX)"  -o pCube1 -ae 1 -uc all ;
    

    This example uses a conversion procedure instead. Just change the line expression -s "YOUR CODE HERE" to modify the expression. Type help expression in the MEL window if you want to know more about the create expression procedure.


    p.s.
    I probably mixed up the deg<->rad conversion math, doesn't matter though. As long as you know the proper function for it. :)
    d.s.
Sign In or Register to comment.