setKeyframe at a time, and force re-evaluation?

setKeyframe at a time, and force re-evaluation?

RFlannery1
Collaborator Collaborator
609 Views
0 Replies
Message 1 of 1

setKeyframe at a time, and force re-evaluation?

RFlannery1
Collaborator
Collaborator

I use "setKeyframe" to set the "translateX" value at a given time.  Immediately afterwards, I query the "translateX" value and "matrix" value at that time.  The "translateX" returns the correct value, but the "matrix" does not.

 

Here is my sample code:

def setValueAtTime(value, time):
node = 'pCube1' cmds.setKeyframe(node, attribute='translateX', time=time, value=value) xValAfter = cmds.getAttr(node+'.translateX', time=time) matAfter = cmds.getAttr(node+'.matrix', time=time) print 'new translateX: {0}\t\t new matrix[12]: {1}'.format(xValAfter, matAfter[12])

for i in range(3):
setValueAtTime(i, 5)

Assuming the cube starts out with an x-translation of 2.0, it prints out the following result:

new translateX: 0.0		 new matrix[12]: 2.0
new translateX: 1.0		 new matrix[12]: 2.0
new translateX: 2.0		 new matrix[12]: 2.0

The documentation for "setKeyframe" says, "Using the value flag will not cause the keyed attribute to change to the specified value until the scene re-evaluates. Therefore, if you want the attribute to update to the new value immediately, use the setAttr command in addition to setting the key."  But "setAttr" doesn't have a time parameter, and I don't want to set the value at the current time.  Also, I don't want to re-evaluate the entire scene because it is large and complicated.

 

Questions:

  1. What is the best way to force the "matrix" attribute to update, without re-evaluating the entire scene?  (I have a couple of hacky workarounds but am hoping there's a better way.)
  2. Why does "translateX" update to the correct value but "matrix" does not?
0 Likes
610 Views
0 Replies
Replies (0)