Python: set a keyframe on parameter
6123
5
2
Feb. 5, 2019 10:07 a.m.
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!
goldfarb
Staff
3464 posts
Joined: July 2005
Offline
Feb. 5, 2019 10:37 a.m.
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
melMass
Member
12 posts
Joined: June 2014
Offline
April 5, 2020 11:09 a.m.
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 ]
gladstein
Member
16 posts
Joined: July 2005
Offline
Dec. 2, 2021 4:11 a.m.
myParm.setKeyframe(setKey) should be myParm.setKeyframe(myKey)
ttpetra
Member
12 posts
Joined: April 2018
Offline
Feb. 2, 2022 6:02 a.m.
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)
ttpetra
Member
12 posts
Joined: April 2018
Offline
Feb. 2, 2022 6:04 a.m.
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 >>>