[Maya] Expression not updating when values are changed in channle box


#1

Hi everyone,

I recently started using expressions need some help/info. I have an expression that uses the position of 2 locators to calculate the angle of a line between the 2 locators. I then use this angle to rotate a joint in a rig. The expression evaluates properly when I move the locator in the viewport, but If I type value for the locators translation in the channel box the angle is off. The same thing happens when I turn on snapping to the grid. I tried setting keys for manually input positions and it is correct when the animation is played back. The biggest problem is that the rig wouldn’t be very usable for the animator if they can’t see if their animation is correct in the viewport until they play it back. Any suggestions would be helpful. I can post more info or the scene files if that will help.

Thanks,
Justus


#2

Hello Justus,

I’ve never seen this problem before, my expressions always evaluate correctly., however, I have seen this with other nodes like the blend color node. Do you have any other nodes connected to your expression?

If not, I would start by seeing if this is the expression or something else causing problems. Try creating the same expression in a new scene with nothing else loaded except what you need (locators and the joints).

If that still fails, try a simple expression like;

locator2.translateY = locator1.translateY;

on 2 locators and see if that updates.
There is always the old test of deleting maya’s preferences and seeing if something was messed up there, just back them up first so you can put them back if needed.

If it turns out to be the expression, can you post it here so we can take a look.

Cheers,

Richard


#3

Thanks for the suggestion, once I’ve had time to test it I’ll post what i learned :D.

Justus


#4

I tried out all you ideas sadly with no change.

I did have a plus/minus/average node for a no flip ik set up, it wasn’t in used in the expression but was used by the joints I’m moving. I also deleted my Maya preferences.


float $hyp;
float $opp;
float $angle;
int $sign;

$hyp = sqrt(pow((foot_dist.translateZ - shoulder_dist.translateZ),2) + pow((foot_dist.translateX - shoulder_dist.translateX),2));
$opp = sqrt(pow((shoulder_dist.translateX - foot_dist.translateX),2));

if(foot_dist.translateZ > shoulder_dist.translateZ)
$sign = 1;
else
$sign = -1;

$angle = asind($opp/$hyp) + 90 + ($sign*180);
print ($opp + " " + $hyp + " " + $angle + "
");

joint5.rotateY = $angle * $sign;

Im trying to make the “shoulder” joint in a arm always point to the hand so that the hand can be planted and moved back and the shoulder joint will rotate with out FK controls. I’ also trying to make the arm only rotate in a along the Y axis form the shoulder(if that makes since). I’m trying to make a mechanical/steam punk spider so I also have some expressions for gears rotating and other things. This is my first try, haven’t really tried any other methods yet. Also I’m using Maya 2011 32 bit and on another machine 2012 64 bit lol, don’t know if that helps. Uploaded the scene file from 2011.

Thanks,
Justus


#5

Hello Justus,

I took a quick look at your file and I don’t think it’s the expression, that seems to work fine, however, it’s the way you have it set up that could be causing you problems. I get no errors in maya, but to me it looks like you have a circular dependancy loop.

Your expression uses a locator (shoulder_dist) which is connected to a child of the same joint you are trying to update. If you delete the parent constraint on this locator, everything updates correctly, of course it’s wrong because the locator is in the wrong palce, but you can type in values and see eveything working.

It’s funny, but last week I had to build a very similar rig, a lego Shelob from their new lord of the rings lego kits. It was a real pain to get everything working because each joint could only rotate on one axis.

To animate the “shoulder” joint as you put it, I didn’t use expressions, I added another joint near the foot which was parented to the shoulder and then added a ik handle that was parented to the foot control. This meant that where ever I placed the foot control, the shoulder would always point at it because it was controlled by the ik.

It would also be possible to set this joint up with aim constraints.

If you really wanted to use your expression, then you could also set up your locator in a similar way, just make sure it’s not connected to the shoulder joint you are controlling.

Cheers,

Richard


#6

Thanks for all the help Richard. I did notice the loop and was kinda confused that it worked at all. I was just giving expressions a try, I’ll try another 1 of your suggestions now. If i remember I’ll post the results.

Thanks again,
Justus

Edit: I actaully just removed the parent constraint from the shoulder locator. Since my idea for the how the shoulder doesnt require it to move, I think I will be able to just parent the locator to the main controller for the entire rig so it will move as it need to. If things change I’ll probably set try a set up like you suggested.


#7

Mel syntax in expressions wont evaluate in realtime, atleast in my experience. It works when you play animation but nothing happens if you move things in viewport or change attribute values. they work in realtime just fine if you use those simple lines like:

node1.translateX = node2.translateY*2;

That’s a reason why i try to avoid expressions as much as possible.

I’ve noticed theres an utility node called angle between. I haven’t used it myself but i think it might do the same trick. It’s also stupid that there isn’t trigonometry nodes natively in maya. If they existed everything would be possible with just node connections.


#8

while working with expression you have to be sure that you start the eveluation of the dependency graph, or your expression wont be triggered or evaluated correctly , if i can i usually prefer to use dependency nodes rather then expressions but from time to time I used them,
If your expression doesnt evaluate correctly try to force the refresh like schleifer shows in his DVD series AFR, which means get a value on the interested node in order to progate the “dirty” connecttion and make maya evaluate the needed graph


#9

I had to read from maya API a bit about the dependency graph cos im not a coder or anything. I understand now what you mean but im still not really sure how to force it in practise

Here’s an example i had the dependency graph eval problem.

I wanted to constrain curves edit points on joints. i didnt find inputs to curves edit points in connection editor so I desided to try an expression.

Here’s the expression.

global proc movep(string $t1, string $t2) {
float $EpPosL[] = xform -q -ws -t $t1;
float $x = ($EpPosL[0]);
float $y = ($EpPosL[1]);
float $z = ($EpPosL[2]);
move $x $y $z $t2 ;
}
movep(“epExpConnect_locator4”, “epExpConnect_curve2.ep[0]”);
movep(“epExpConnect_locator5”, “epExpConnect_curve2.ep[1]”);
movep(“epExpConnect_locator6”, “epExpConnect_curve2.ep[2]”);

Any idea how to force the evaluation in this situation?


#10

i will have to test it meanwhile have you tested the script running it n the script editor?


#11

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.