Let me preface this with the fact that I am EXTREMELY new to MEL scripting, and know almost nothing of the syntax or even how to properly set up what I'd like to do. I've managed to make more sense of the Expression editor as it feels much more intuitive than MEL scripting, particularly when creating animations over time.
That said, I need to be able to use a MEL script that will create an expression, mainly so that I can assign similar expressions to multiple objects, and only have to change a variable in one place in the script, rather than having to update every expression when I make a change.
Here's the original expression for one of the objects that works exactly as I would like it to:
$A = 1.5;
$B = 1.5;
$b = deg_to_rad(0);
$b1 = deg_to_rad(360*time*4);
$b2 = $b1/2;
$s = 11;
if (time > 5)
$b = (deg_to_rad(36*time*4));
if (time > $s)
$b = deg_to_rad(36*$s*4);
SphereLeft.translateZ = cos($b)(($Asin($b1))+($B*sin($b2)));
Now I would like to do exactly this, but instead of using an expression, I would like to start the scene with no animations or expressions, and execute a MEL script to create exactly this animation over time. I've tried several different things, and I always get an error, or I'll manage to get the script to create the expression, but the expression doesn't do anything, it just keeps translateZ at 0 every frame...
This is what I have as a script so far:
float $A = 1.5;
float $B = 1.5;
int $time = currentTime -q
;
float $b = deg_to_rad (0);
float $b1 = deg_to_rad(360*($time/(float)24)*4);
float $b2 = $b1/2;
int $s = 11;
if (($time/(float)24) > 5) $b = (deg_to_rad(36*($time/(float)24)*4));
if (($time/(float)24) > $s) $b = deg_to_rad(36*$s*4);
float $L = cos($b)(($Asin($b1))+($B*sin($b2)));
expression -string "SphereLeft.translateZ = $L";
If you print out variable $L, it returns the correct number for each frame of animation, so I know everything is working correctly right up until I actually want to make an expression. However, the expression, even with $L, does not change or update at all over time. What am I missing? Perhaps I just really don't understand how scripting works vs. expressions...
Thanks ahead of time for any help!