PDA

View Full Version : query if attribute is changing over time


misterwolfy
10-03-2010, 06:46 AM
Is it possible to query whether an attribute is changing over time?

For instance, get the result 1 if the value of someNode.translateX changes value between frame 1 and frame 2, and the result 0 if there is no change.

Thanks for reading!

NaughtyNathan
10-03-2010, 09:40 AM
depends on where and how you need to do it I suppose...
you can do a `getAttr -time` so you could query any attribute value at frame 1, and at frame 'n' and compare the two values.
Or you can create a scriptJob to execute on -attributeChange, so that could tell you.
However, if you wanted something for an expression I'm not sure if either of these two methods would be recommended... you could always just store the first value as a variable, then subtract the value at the next frame, and the result will be 0 (false) if they haven't changed, or true if they have (any non-zero value is true in MEL or python).

:nathaN

misterwolfy
10-03-2010, 10:53 AM
Yes I have been working on something similar. The only thing that is confusing me is that the variable has to be declared at every frame, not sure if that resets the values. Anyway this is as close as I could get. Gives me an error:

// Error: An execution error occured in the expression is_it_moving_. //
// Error: Division by zero. //


int $position;
int $posCheck;
$position = (polyCube_0.translateX + polyCube_0.translateY + polyCube_0.translateZ);
int $theTime = `currentTime -query`;
if( $theTime != 0 )
$posCheck = ( $position / $posCheck);
if( $posCheck != 1)
print "not 1";
else
print "1";
$posCheck = $position;

misterwolfy
10-03-2010, 10:59 AM
UPDATE:

This seems to work based on your suggestion of subtraction.


int $position;
int $posCheck;
int $posCheck2;
$position = (polyCube_0.translateX + polyCube_0.translateY + polyCube_0.translateZ);
int $theTime = `currentTime -query`;
if( $theTime != 0 )
$posCheck2 = ( $position - $posCheck);
if( $posCheck2 != 1)
print "not 1";
else
print "YES it's 1";
$posCheck = $position;

CGTalk Moderation
10-03-2010, 10:59 AM
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.