19 February, 2010

Interesting Notes @ Expression Node

Expression in maya is basically a node that takes inputs and processes them with MEL and gives output.

If you want to create an Expression node without connection to the actual objects, you can do the following.
.O[0] = .I[0];
.O[1] = .I[1];
.O[2] = .I[2];
After this you can connect the inputs and outputs to this Expression node manually through connection editor. If you want your expression to be evaluated only based on value change of inputs then you can change expression to be evaluated "On Demand" instead of always. With always "time" node will be connected to expression resulting in evaluation when time changes (i.e. also while animation is playing).

Also, you should note that if you rename the nodes, expression automatically updates the object names in the expression (if you have used direct value assignments e.g. obj1.tx = obj2.tx).

It is also possible to have input connections to expression node from other nodes even if we are not using them later in expression. To do this you can just assign the attribute value to a variable instead of another attribute. So you can create an expression just with $myVar = $myCtrl.attr. We can use this technique to evaluate expression when an attribute changes (with evaluate = on demand). This is a good alternative to a scriptJob for attribute change!! I discovered this technique while trying to solve bidirectional dependency using nodes in my independent study in spring'09. I could not manage to make bidirectional stuff in a perfectly working solution using just maya nodes. But, I have not given up.

edit:
Few Notes:
  • Only those nodes will be renamed in expression that has direct assignment values.
  • It is required to compute some kind of output to be able to call expression, without any output connection expression will not be computed.
  • You can use any kind of input and any kind of output connection even if they are not related.

No comments:

Post a Comment