Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Update Expression automatically when value changes in another attribute

Update Expression automatically when value changes in another attribute

Anonymous
Not applicable
2,107 Views
7 Replies
Message 1 of 8

Update Expression automatically when value changes in another attribute

Anonymous
Not applicable

Hi All, 

What I'd like to do is control the translation limits for a control based on the twist attribute of a second control. I've created an expression within the Expression Editor and it works once when I hit Edit. However, I want it to evaluate every time the twist value changes. I'm pretty sure I've seen it done before but I'm drawing a blank on how to do it. 

float $twistValue = `getAttr("torso_CTL.twist")`;

if ($twistValue < -10) 
	transformLimits -tz 0 200 -etz 1 1 CTRL_throttleHandle;
else if ($twistValue >= -10 || $twistValue <= 10) 
	transformLimits -tz 50 250 -etz 1 1 CTRL_throttleHandle;
else 
	transformLimits -tz 100 300 -etz 1 1 CTRL_throttleHandle;
0 Likes
Accepted solutions (1)
2,108 Views
7 Replies
Replies (7)
Message 2 of 8

lee.dunham
Collaborator
Collaborator

Expressions are different to scripts, and you usually try to avoid using things like getAttr and setAttr.

Instead, you access the attribute directly, and I think it will provide the behaviour you are looking for.

if torso_CTL.twist < -10 {

...

0 Likes
Message 3 of 8

Anonymous
Not applicable

Thanks @lee.dunham 

Accessing the attribute directly does help with setting up the expression, but it still doesn't apply the changes automatically when I change the value of torso_CTL.twist. I thought perhaps there was a way to do this with expressions, but I'm starting to consider that there isn't.

0 Likes
Message 4 of 8

lee.dunham
Collaborator
Collaborator

I don't have access to Maya atm, but you could look at a scriptJob tied to attributeChanged instead?

0 Likes
Message 5 of 8

Anonymous
Not applicable

Hi @lee.dunham 

I've been on a big project with a looming deadline so I haven't had a chance to try your suggestion yet but I'll let you know how it goes when I do.

 

Thanks!

0 Likes
Message 6 of 8

olarn
Advocate
Advocate
Accepted solution
Message 7 of 8

Anonymous
Not applicable

@olarn I ended up just using the node editor to get the results that I wanted. Since I was dealing with 3 scenarios rather than a simple if / else situation, I had to get creative with the nodes. 

Message 8 of 8

olarn
Advocate
Advocate

Nice.

 

I'd like to interject for some more that implement as nodes has one more hidden benefits -- free parallelization.