0
$\begingroup$

My situation right now: I am able to deselect all objects with Python by doing bpy.ops.object.select_all(action='DESELECT').

My goal: Deselect all Keyframes of the active object with Python.

$\endgroup$

2 Answers 2

1
$\begingroup$
x = bpy.context.area.type
bpy.context.area.type = 'DOPESHEET_EDITOR'
bpy.ops.action.select_all(action='DESELECT')
bpy.context.area.type = x

This is a basic step of course the better solution lies in adding the below process

[i.keyframe_points for i in bpy.context.object.animation_data.action.fcurves if i.select == True]

and turning the knob select_control_point off Ref Library

$\endgroup$
3
$\begingroup$

Deselect all keyframe points and handles

Helper method to deselect all fcurves and their keyframes and handles of an objects action.

import bpy


def deselect_all_keyframes(ob):
    ob.animation_data_create()
    action = ob.animation_data.action

    if action:
        # deselect all fcurves
        action.fcurves.foreach_set)
                "select",
                (False,) * len(action.fcurves),
                )
        # deselect all keyframes
        for fc in action.fcurves:
            for select in ("select_control_point",
                           "select_left_handle",
                           "select_right_handle",
                               ):
                fc.keyframe_points.foreach_set(
                        select, 
                        [False] * len(fc.keyframe_points)
                        )

# test call on context object                        
deselect_all_keyframes(bpy.context.object)
$\endgroup$

You must log in to answer this question.