Querying Selected Keyframes in Python

   2687   2   1
User Avatar
Member
3 posts
Joined: Nov. 2013
Offline
Hey there, this may be a silly question but I can't find any information about it online. I'd love to be able to set slope and angle of selected keyframes using either a shelf tool or python panel, but I can't seem to find out how to get the selected keyframes in the Python Shell. hou.SelectedNodes() seems to only return the selected node in the Network Editor.

Any help on how to proceed would be appreciated!

Jake
User Avatar
Member
3 posts
Joined: Nov. 2013
Offline
Just bumping this topic because I ran into the same idea again and found a solution this time in the help files, in case anyone else would like to know. You just have to find the Channel Editor (Animation Editor) using python, and once there the Channel Editor has a graph() function to give you the current graph as an object. The channel graph lets you run selectedKeyframes() to query the currently selected keyframes.

The help files have a good code example to get you started: [www.sidefx.com]

channel_editor = hou.ui.paneTabOfType(hou.paneTabType.ChannelEditor) # find any pane tab that is a Channel Editor
keyframes = channel_editor.graph().selectedKeyframes() # get the graph's selected keyframes in a dict called keyframes
for parm in keyframes.keys():
    for key in keyframes[parm]:
        key.setValue(2 * key.value()) # this can be anything, like setExpression("bezier()")
        parm.setKeyframe(key)

Anyways hope this helps folks figure out some python scripting options in Houdini!
Edited by jakemadeathing - Nov. 1, 2018 12:05:06
User Avatar
Member
22 posts
Joined: Oct. 2018
Offline
Do you know how to query selected keyframe handles? If I just select the incoming handle of a keyframe the above doesn't return anything
  • Quick Links