3
$\begingroup$

enter image description here

I'm looking for something similar to this, or other:

len(bpy.context.selected_objects)
$\endgroup$
0

1 Answer 1

2
$\begingroup$

It seems there is no direct way to get a list of the selected key frames but you can loop through them and check point by point:

for one object and current action :

import bpy

obj = bpy.context.object
action = obj.animation_data.action

for fcurve in action.fcurves :
    for p in fcurve.keyframe_points :
        print(p.co[0], p.select_control_point )

more detailed :

import bpy

obj = bpy.context.object             #active object
action = obj.animation_data.action   #current action

print(action.name)
for g in action.groups :
    print("",g.name)
    for channel in g.channels :   # channel is fcurve
        print("  %s[%s] :"%(g.name,channel.array_index))
        for p in channel.keyframe_points :
            print("    is selected at frame %d %s"%(p.co[0], p.select_control_point ))

for the whole scene you cane use :

for action in bpy.data.animation_data.actions :

for the action editor or dopesheet :

import bpy

for area in bpy.context.screen.areas:  #loop through areas
    if area.type == 'DOPESHEET_EDITOR':   #find the dopesheet
        dopesheet = area.spaces[0]
        print(dopesheet.type)
        action = dopesheet.action
        for fcurve in action.fcurves :
            for p in fcurve.keyframe_points :
                print(p.[0],p.select_control_point)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .