Python: set a keyframe on parameter

   5318   5   2
User Avatar
Member
10 posts
Joined: April 2016
Offline
Hello.

I have what i would believe is a simple question.

how do I set a keyframe on a parameter?
I've tried a lot of variations on the code below:
hou.cd('/obj/geo1/file3')
fileParm = hou.node('../file3').parm('file')
fileParm.setKeyframe(hou.BaseKeyframe(1))

Tried using hou.Keyframe and without it.

Looked through the docs, looked through the cookbooks with no luck.
I really have a hard time figuring out how it is so difficult.
I've made python scripts in maya for many years and are confused that I'm stuck with this one.
Thanks!
User Avatar
Staff
3455 posts
Joined: July 2005
Offline
you can see how keyframes are set in python by using asCode() on a node that has keys

put down a null
add a key on ty at 0, add a key on frame 24, set the value to 5

in the Python Shell
parm = ou.parm('/obj/null1/ty')

print parm.asCode()

you'll see the code
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
12 posts
Joined: June 2014
Offline
How to set keyframe by python

myParm = hou.parm("/obj/geo1/tx")

myKey = hou.Keyframe()
myKey.setFrame(0) # or myKey.setTime()
myKey.setValue(5)

myParm.setKeyframe(setKey)

This is the minimum requirement for keyframes, a lot more options are available to deal with slope, accel, etc… :
https://www.sidefx.com/docs/houdini/hom/hou/Keyframe.html [www.sidefx.com]
User Avatar
Member
16 posts
Joined: July 2005
Offline
myParm.setKeyframe(setKey)

should be

myParm.setKeyframe(myKey)
User Avatar
Member
12 posts
Joined: April 2018
Offline
gladstein
myParm.setKeyframe(setKey)

should be

myParm.setKeyframe(myKey)

Can you guide on how to set multiple keyframes (the above example sets a single keyframe)
User Avatar
Member
12 posts
Joined: April 2018
Offline
My question is related to this thread.

How do I set multiple keyframe?
I tried this approach but it returned an error.

>>> zBox = box.parm('tz')
>>> zBox.keyframes()
()
>>> keys = zbox.keyframes()
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'zbox' is not defined
>>> keys = zBox.keyframes()
>>> for key in keys:
... key.setFrame(key.frame()+1)
... key.setValue(key.frame()+2)
... zBox.setKeyframes(keys)
File "<console>", line 4
zBox.setKeyframes(keys)
^
SyntaxError: invalid syntax
>>>
  • Quick Links