Animation Editor

Or graph editor in Maya speek.

  • Set Keyframe : Alt LMB (click the parm)
  • Delete Keyframe : Ctrl LMB (click the parm)
    • It will leave the current value (of the animation curve as) a static value
  • Reset to Default : Ctrl MMB (click the parm)
  • Open Animation Editor : Shift LMB (click the parm)
  • Edit Channel Properties : Select the channel, with the mouse pointer over the animation editor press Alt E
    • Or RMB click the channel > Channels > Channels Properties
    • It is in this widget you can set how the curve will extrapolate before & after the keyframes

Copy/Paste Keyframes

  • Shift LMB click the parm to open the animation editor
  • Select the keyframes and Ctrl C to copy
  • Shift LMB click the parm that you want to paste to
    • This will open up the animation editor, with the channel selected in the channel list
  • Ctrl V paste the keyframes.
    • Note that the keyframes will be pasted where the current time marker is located in the animation editor.

Python

Set Keyframes

parm = node.parm('ty')

key_0 = hou.Keyframe()
key_0.setFrame(1)
key_0.setValue(0)
key_0.setSlope(10)
key_0.setAccel(1)
parm.setKeyframe(key_0)

key_1 = hou.Keyframe()
key_1.setFrame(24)
key_1.setValue(1)
parm.setKeyframe(key_1)

Slopes & Accel

I wrote a script to ease a tpose into the first frame of some mocap data so I needed a way to programatically set the slope of the anim curves to linear/straight. One quick and dirty way to do this, is to set the accel of the keyframes to 0. This will have the effect “scaling” down the “slope tangent handle” to 0, resulting in a straight interpolation into the next keyframe.

But I was curious of how to calculate the slope and accel myself. To calculate the slope of a line between two points we divide the rise over run. Meaning the delta of the y (the parm value) divided by the delta of the x (the time). Note that we must multiply the frame delta with timeinc to get the delta in seconds instead of frames. To explore how to calculate the accel values I set two keyframes, and pressed the button in the animation editor to make the interpolation straight. Visually it looked like the handles were set to 1/3 of the length between the coordinates. Below is a snippet of how I calculated the values using Python.

import math

start_frame = 1
end_frame = 10

start_val = 0.0
end_val = 42.0

fps = 24
timeinc = 1.0/fps

rise = end_val-start_val
run = (end_frame-start_frame)*timeinc

slope = rise/run

accel = math.sqrt(rise*rise+run*run)/3.0

print('slope -> {}'.format(slope))	# slope -> 112.0

print('accel -> {}'.format(accel)) # accel -> 14.000558024593163


# Houdini anim editor values: slope -> 112   accel 14.0006



Example

Camera Switcher

switcher_node = hou.node('/obj/switcher1')
switch_parm = switcher_node.parm('camswitch')

info_list = [
{'frame':1, 'value':0},
{'frame':10, 'value':1},
{'frame':20, 'value':2},
{'frame':30, 'value':1},
{'frame':40, 'value':0},
]

switch_parm.deleteAllKeyframes()

for info_dict in info_list:

    key = hou.Keyframe()
    key.setFrame(info_dict['frame'])
    key.setValue(info_dict['value'])
    key.setExpression('constant()')
    switch_parm.setKeyframe(key)