From b2aa36485bbca0d755fc2ff816639714f67a2637 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Thu, 1 Feb 2024 16:14:05 +0100 Subject: [PATCH] Fix: Regression of Python API for anim.keyframe_insert Caused by #113504 The `type` property has been removed from the operator, but of course that is a breaking change in 4.1. (e.g. reported here: #117547) At the time of making the patch, I wasn't sure how to handle all cases but it turns out its not complicated. I've added back the property with the following logic. * Try to get the `KeyingSet` from the `type`. * `type` defaults to 0 which means the `ANIM_keyingset_get_from_enum_type` will get it from the scene. * If the scene doesn't have one, or a valid index isn't passed in the `KeyingSet` will be a `nullptr` in which case it inserts from the user preferences. Pull Request: https://projects.blender.org/blender/blender/pulls/117718 --- source/blender/editors/animation/keyframing.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/animation/keyframing.cc b/source/blender/editors/animation/keyframing.cc index 61c260424d0..20bd805a542 100644 --- a/source/blender/editors/animation/keyframing.cc +++ b/source/blender/editors/animation/keyframing.cc @@ -374,7 +374,8 @@ static int insert_key_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); /* Use the active keying set if there is one. */ - KeyingSet *ks = ANIM_keyingset_get_from_enum_type(scene, scene->active_keyingset); + const int type = RNA_enum_get(op->ptr, "type"); + KeyingSet *ks = ANIM_keyingset_get_from_enum_type(scene, type); if (ks) { return insert_key_with_keyingset(C, op, ks); } @@ -396,6 +397,13 @@ void ANIM_OT_keyframe_insert(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* Allows passing in a keying set when using the Python operator. */ + PropertyRNA *prop = RNA_def_enum( + ot->srna, "type", rna_enum_dummy_DEFAULT_items, 0, "Keying Set", "The Keying Set to use"); + RNA_def_enum_funcs(prop, ANIM_keying_sets_enum_itemf); + RNA_def_property_flag(prop, PROP_HIDDEN); + ot->prop = prop; } static int keyframe_insert_with_keyingset_exec(bContext *C, wmOperator *op)