Mel - Maya Embedded Language

Hints when Writing Expressions
  • Avoid using setAttr and getAttr, instead directly set the object's attribute.
    $float $myScale = box.scale;
    box.scale = $myScale;
  • Use shorthand attributes to speed up expression writing.
    translateX = tx
    translateY = ty
    translateZ = tz

    rotateX = rx
    rotateY = ry
    rotateZ = rz

    scaleX = sx
    scaleY = sy
    scaleZ = sz

    visibility = v
  • Two useful functions to use when writing expressions are time and frame. time = frame/fps
  • time returns the current time (seconds) as the animation plays. For instance, if you are on frame 60 and you have set your fps to 30 then you would get a 2 returned.

    frame returns the current frame number you are on.

    Ball7.tx = frame/2; = time * 3;

  • To debug an expression, insert print commands in your expression at points were you would like to know the value of a variable or object attribute.
  • Runtime Expressions are executed on every frame. Be concise in your codeing. Executing a loop on every frame could be slow.
  • Expressions can only access attributes of type float, int, or boolean.
  • You cannot write an expression to change an attribute that is keyed, constrained or attached to a motion path. You can write an expression to alter a different attribute on that same object. You may need to break connections on the object's attribute if you want to use it in an expression.

  • Runtime expressions are typically used to manipulate attributes rather than create or delete objects. If you must create or delete objects, make sure you delete the expression after it is run the first time or it will continue to make more each time.
  • If you are writing an expression under the by object/attribute name window view. You can omit the object's name and simply call the attribute that you are setting.
    Maya understands that tx = 10; would be the same as ball.translateX = 10;