After you’ve typed an expression in the Expression Editor, you click the Create or Edit button to compile the expression. Compiling the expression checks it for syntax errors and converts it to a form Maya can execute when you rewind or play the animation. After being compiled, the expression executes for the current frame.
By default, an expression also executes whenever the current animation time or frame changes. For example, an expression executes when you rewind or play the animation. The expression executes once for each time the animation frame or time changes. To stop this default evaluation, set the expression node Evaluation mode in the expression editor to On Demand.
An expression also executes when an attribute referenced directly in an expression changes value. For example, if your expression assigns a sphere’s translateX attribute to another attribute and you move the sphere in an X-axis direction, the expression executes upon each increment of the sphere’s movement.
pCube1.tx = pSphere1.tx * 3.0
When you select an object other than a particle shape node, you can use the Evaluation drop-down menu in the Expression Editor to set when an expression executes. (If you select a particle shape node, the Expression Editor dims this menu. For details on particle shape node expressions, see About particle expressions.)
When writing an expression, you can access object attributes either directly or with MEL (see Note, below).
Directly:
pCube1.tx = pCube2.ty * 3.0
MEL:
setAttr pCube1.tx (`getAttr pCube2.ty`* 3.0)
When Evaluation is set to On Demand, the expression calculates only when the input connection of your expression changes (in the example above, when the value of pCube2.ty changes), or when you click Edit in the Expression Editor. When Evaluation is set to Always, every frame change triggers an evaluation even if nothing in the scene has changed.
Setting Evaluation to Always only forces evaluation of the expression when time changes. Thus, using a solution that includes a MEL expression and Evaluation set to Always does not evaluate when manipulating the objects in the scene view, unless it is during Interactive Playback.