Querying selected keyframes in python


Hey guys,

Is there a way to query selected keyframes in Maya’s timeline?

Like if you made a selection like this in maya:


And then you needed to run a for loop all every selected keyframe. How would you go about doing that?


I found this which seems to work with a quick test:

import maya.cmds as cmds
import maya.mel as mel

aTimeSlider = mel.eval('$tmpVar=$gPlayBackSlider')
timeRange = cmds.timeControl(aTimeSlider, q=True, rangeArray=True)

This is perfect clesage! Thank you so much!


One other thing I learned when I wrote a little keyframe mover tool. If you use the keyframe() command, but you do not specify a range, it will automatically use all keyframes, OR a selection that you have in the timeline or the graph editor. Full range, full selected animation curves, or selected keyframes.

So depending on what you are doing, or if this is an interactive end-user tool, you might not need to loop over anything.