Python modify Keyframe (vs. delete old and create new one)

   1400   4   2
User Avatar
Member
147 posts
Joined: Jan. 2016
Offline
Please, I tried to use these methods to update certain Keyframe value and frame:

setValue()
setFrame()

But it seems, that it cannot be done directly like this. Do we have to delete the old one and create a new one in order to "modify" a Keyframe?

deleteKeyframeAtFrame()
setKeyframe()
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
Just testing this out real quick, it seems what you have to do is something like this:

p = hou.parm( "/obj/null1/scale" )
keys = p.keyframesInRange( 48, 48 ) # Find the keyframe on frame 48 
k = keys[0] # Get the first entry from the keys list

k.setValue( 1.2 )
p.setKeyframe( k )
User Avatar
Member
147 posts
Joined: Jan. 2016
Offline
Hello Krueger, thank you very much.
You are right, as long as you don't change the setFrame()

The code below creates a duplicate Keyframe. I assume that we have to delete the original Keyframe.

p = hou.parm( "/obj/null1/scale" )
keys = p.keyframesInRange( 48, 48 ) # Find the keyframe on frame 48 
k = keys[0] # Get the first entry from the keys list

k.setFrame( 24 )
p.setKeyframe( k )
User Avatar
Member
8597 posts
Joined: July 2007
Online
ikoon
The code below creates a duplicate Keyframe. I assume that we have to delete the original Keyframe.
doing it one by one can get tedious

I usually get a copy of all keys on the parm, modify them, then delete all parm keys and set to modified keys

keys = p.keyframes()

for key in keys:
    key.setFrame(key.frame()+10)

p.deleteAllKeyframes()
p.setKeyframes(keys)
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
147 posts
Joined: Jan. 2016
Offline
Thank you so much tamte and krueger.
I didn't understand it very well yesterday, but now the system makes sense.

I have sent RFE to SideFX, to consider adding a little notice to the hou.Keyframe docs and adding the examples which you posted here.
  • Quick Links