Setting keyTimeValue.keyTime with setAttr

379 views
Skip to first unread message

Eduardo Grana

unread,
Apr 5, 2015, 12:03:48 PM4/5/15
to python_in...@googlegroups.com
Hello Guys,

Just a simple question.
I'm trying to set the time for a keyframe with
setAttr since i'm exporting and importing some curva data,
and with keyframe is a little more verbose and less code friendly
(for example keyframe -option over -index 0 -absolute -timeChange 2 pSphere1_translateX ;)

So I'm running into this error when i do
timeVar = 0
crv = 'pSphere1_translateX'
mc.setAttr(crv+'.keyTimeValue[0].keyTime', timeVar)
# RuntimeError: Maya command error #

and maybe you guys can give me some tip about whats going on.
Here is the simple code for you to test:

http://pastebin.com/uyasZfmg

Thanks is advance.
Cheers!

--

Justin Israel

unread,
Apr 6, 2015, 8:05:52 PM4/6/15
to python_in...@googlegroups.com
Using the keyframe command doesn't seem too verbose or less code friendly to me. It feels like you have a lot of control over what you are changing, versus having to format a string in setAttr:
timeVar = 2
crv = 'pSphere1_translateX'
mc.keyframe(crv, e=True, index=(0,), o="over", tc=timeVar)
Does this not work for your needs?


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACt6GrkG_Eupz%3DAoi5%3Dp5a90jQF1pxXZmS9hZAa42qtSwK%3DnnA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Eduardo Grana

unread,
Apr 6, 2015, 11:08:43 PM4/6/15
to python_in...@googlegroups.com
Hey Justin,
Thanks for the reply.
Yes, I ended up doing some command call like that, but i was very curious about
what was the 'Maya command error' about, and how to set that 'time' attribute.

Another thing that i noticed, is that you get different data depending how you query,
for example

import maya.cmds as mc

# createa a sphere and set a keyframe
sphere = mc.polySphere()[0]
mc.setAttr(sphere+'.r', 17,17,17)
 
mc.setKeyframe()
 
 # get animation curve
crv = mc.listConnections(sphere+'.ry')[0] # rotation curve this time
 
# query values for key 0
time0, value0 = mc.getAttr(crv+'.keyTimeValue[0]')[0]

value1 = mc.getAttr(crv+'.keyTimeValue[0].keyValue') # same keyframe as before

print value0, value1, value0 == value1 # value0 is in radians and value1 is in degrees
>>> 0.296705972839 17.0 False

So if you want the values that you see in the graph editor, you have to be careful how you query.
Cheers!
Eduardo




For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages