FORUMS: list search recent posts

When to use assignment and when to use getAttr?

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Steve Sayer
When to use assignment and when to use getAttr?
on Feb 27, 2006 at 2:18:46 am

Hi, folks--an Expression question has me stumped.

It's not a how-do-I-do-this question, it's a WHY-do-I-do-this question.

The following expression works just fine:
float $test;
$test = locator1.translateX;
And the following expression also works fine:
int $test;
$test = particleShape1.count;
So far so good: it's easy to assign the value of an attribute to a variable, and as the animation plays and the attribute changes, the variable changes appropriately, keeping track of the correct value. But what happens when I try to assign the value of the totalEventCount attribute to my variable instead?
int $test;
$test = particleShape1.totalEventCount;
If this expression is run in a scene, the variable $test does NOT update properly as the animation plays. It stays obstinately equal to zero. Can anyone confirm this result? (You have to create an event for the particles first, of course.)

Using a getAttr command to capture the correct value works fine:
float $test;
$test = `getAttr particleShape1.totalEventCount;`
As a workaround, this is not a problem at all to implement--but I just don't understand WHY it's necessary. Also, I seem to recall having this problem with other attributes in the murky past, but I can't recall specifics. I have tried Googling the issue, but came up empty.

Anyone know what's 'special' about the totalEventCount attribute, and why I have to use getAttr to assign its value to a variable properly? And what other attributes want this special red-carpet treatment?

Thanks for any clues,

-Steve


Return to posts index

Thomas Rydberg
Re: When to use assignment and when to use getAttr?
on Mar 6, 2006 at 9:29:49 pm

Hi Steve,

I've noticed this too. I think it's an inconsistency due to, perhaps, extending/adding other properties later on that weren't initially accounted for when the language was first developed. Also, it may save on memory, having to keep track of fewer variables unless a command explicitly calls for a value.

- Tom

******* AnimationMentor.com student *******

"Learning to animate anywhere in the world

from the world's best animators."

Pixar, ILM, Disney, Dreamworks and more.

***********************************************



Return to posts index

Steve Sayer
Re: When to use assignment and when to use getAttr?
on Mar 9, 2006 at 3:24:59 pm

Thanks Tom. Yes, it was very surprising to me, too. Someone on HighEnd3D suggested another workaround, which is to use a MEL command to mark the attribute 'dirty' which forces reevaluation. Works like a charm.

Odd!

-Steve


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]