Mel: Expressions

From wikinotes

Intro to Expressions:

Expressions vs Mel

Expressions: Expressions are directly linked to an attribute, and can calculate faster than a melscript since they refresh only when they need to.

ex:
translate.x = y-1 + z;
(this script only refreshes when y or z attributes change)


Mel: Mel needs to search every cycle to see if an attribute has changed, and then change it. This wastes CPU cycles.

ex:
while (translate.X != 0){
   setAttr translate.X = y-1 + z;
}

When to use an Expression:

When you have two objects that will need to be refreshed frequently, if you can use utilityNodes or SetDrivenKey those are generally better alternatives since they run faster



Creating a sample Expression:

  • Create two polygon cubes, animate one cube moving upwards in Y.
  • Window > Animation Editors > Expression Editor
  • Change SelectFilter to by Expression Name:
  • type a name for your expression
    • in expression: type
    • pCube1.translateX = pCube2.translateY;
  • click New Expression