Expressions
Expression Setup
Visibility Expression
I am using this expression that is simply turning on and off groups based on
the pound_CTRL.model attribute, which is an integer. It works just fine in
the scene, though you need to scrub the timeline to see it update since it's
an expression.
My problem is that when doing a batch render, it looks like all groups are
invisible, so either the expression isn't updating, or the last two lines
are not evaluating. The only frame that renders correctly is the frame that
the file was saved on.
I tried a pre render mel like currentTime -update Yes; and dgdirty -a
I tried just setting the current time, but no dice.
I could bake all of the visibility, but I don't want to.
I read somewhere that expressions don't like setAttr, and maybe I can set
the variable without using setAttr in the expression.
Anyone have any ideas?
int $numGrps = 50;
int $b;
for ($b=1; $b<=$numGrps; $b++){
setAttr ("grp"+ $b +".visibility") 0;
}
int $mod = (`getAttr pound_CTRL.model`);
setAttr ("grp"+ $mod +".visibility") 1;
you may try baking out to keys the visibility on the objects, and then
rendering...
-=s
I don't think I can use direct connections, and can't think of a utility
node that would do this sort of thing, unless I make a crazy network of
condition nodes.
I had a thought though. I made a script node that calls a proc when that
controlling attribute changes. Then I put that proc name in the prerender
mel as well? I'm giving it a try.
I can just write functionName(); in the preRender Mel spot, right?
you can make the connection using animation curves.
each object gets a curve that goes from 0 to 1 to 0, and then offset each by
1
ie:
obj1 frame 0 = 0 , frame 1 = 1, frame 2 = 0
obj2 frame 1 = 0 , frame 2 = 1 , frame 3 = 0
etc.....
now connect the mod attribute into the input of ALL the animations
animation curves.
hth
-=s
sounds like a plan.
It's frustrating that I'm pretty sure that the script would work, and it
would be easy to expand upon. But this would certainly work.
I'll do that.
Setting Up Multiple Expressions on Multiple Objects
import maya.cmds as mc
for i in range(1, 5):
mc.expression( s='pSphere' + str(i + 1) + '.ty = pSphere' + str(i) + '.ty' )
in Mel, and allowing for more complicated expression setups....
for($i = 1; $i <=1; $i++){
string $cmd = "pSphere" + ($i + 1) + ".ty = pSphere" + $i + ".ty;";
/ERROR CHECK : print $cmd;
expression -s $cmd;
}
int $i;
for($i = 1; $i <=6; $i++){
string $cmd = "if (motionPath" + $i + ".uValue <= .496){file" + $i + ".frameExtension = " + $i + ";}else{file" + $i + ".frameExtension = " + ($i + 1) + ";};";
expression -s $cmd;
}
Slow Down a Random Expression
You can do this using an 'if' statement and the modulus operator:
if (frame % 5 == 0)
XXX.tx = rand(-1,1);
The modulus operator calculates the remainder of the division of the frame number by five. Only when the frame count is a multiple of five will this remainder be equal to zero. When that happens, the conditional statement executes, and the object is assigned a new position.
(S. Sayer)
FAQ
Is it better to set up multiple short expressions, or one long expression?
Resources
Mel and Expressions (Autodesk)