Programmatically accessing selected keyframes from AnimGraph
949
1
1
cval
Member
161 posts
Joined: May 2015
Offline
March 26, 2022 10:56 a.m.
Greetings everybody,
I am trying to access selected keyframes from the Animation Editor using this code from the documentation:
channel_editor = hou . ui . paneTabOfType ( hou . paneTabType . ChannelEditor )
keyframes = channel_editor . graph () . selectedKeyframes ()
for parm in keyframes . keys ():
for key in keyframes [ parm ]:
key . setValue ( 2 * key . value ())
parm . setKeyframe ( key )
However, the "selectedKeyframes" method always returns empty, no matter how many keyframes I select.
Any idea of what I could be doing wrong? Maybe the "ChannelEditor" is not the same as the "Animation Editor"?
Thanks in advance for any help on this subject
cval
Member
161 posts
Joined: May 2015
Offline
April 19, 2022 3:43 p.m.
Big thanks to Guillaume from SideFX who could indicate me the problem with my code and how to fix it! I am posting the solution here in case it can help other persons.
The problem was accessing the correct channel_editor (animation_editor). Here is an example that returns selected keyframes from the pane under the cursor:
def get_selected_keyframes ():
pane_tab = hou . ui . paneTabUnderCursor ()
anim_editor = pane_tab . graph ()
return anim_editor . selectedKeyframes ()
Just make sure that your mouse is over an animation editor while executing this code