From 78b9a8c7b993991c22ac2bd1ffbfaf1d896e4431 Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Tue, 28 Sep 2021 14:07:02 +0200 Subject: Add an option to silence bpy.ops.anim.keyframe_delete_v3d when used in Addons The issues: 1.) When we want to remove keyframes from a range of frames in an action, then we can use bpy.ops.anim.keyframe_delete_v3d to remove the keys frame by frame. However, whenever the operator hits a frame with no keyframes, then it generates an error. While when it hits a frame with keyframes, then it reports the numbner of removed keys. This creates a lot of unnecessary noise in the Blender console. 2.) Furthermore a related issue is that WM_event_add_notifier() is called also when no frames where removed. This seems to significantly slow down the removal of keyframes in a range of frames at least when i use vscode for debugging. A proposal for improvement: This patch adds an attribute 'confirm_success' which controls if the operator reports back what it did (or did not) while executing. Silent mode would then be called like this: bpy.ops.anim.keyframe_delete_v3d(confirm_success=False) Note: confirm_success is True by default so this patchj does not change the behavior of Blender, it only gives the option to scripts. 3.) Personal note: I have chosen the attribute name to be equal as it is used in other related operators. However i rather would rename the attribute to "verbose" (preferred) or "with_confirm". But i let this to be decided by the reviewers. Thanks for your time to review! Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D12629 --- source/blender/editors/animation/keyframing.c | 30 +++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 8dc4aed9f0e..1ef7ee755ea 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -2107,10 +2107,12 @@ static int delete_key_using_keying_set(bContext *C, wmOperator *op, KeyingSet *k return OPERATOR_CANCELLED; } + PropertyRNA *prop = RNA_struct_find_property(op->ptr, "confirm_success"); + bool confirm = (prop != NULL && RNA_property_boolean_get(op->ptr, prop)); + if (num_channels > 0) { /* if the appropriate properties have been set, make a note that we've inserted something */ - PropertyRNA *prop = RNA_struct_find_property(op->ptr, "confirm_success"); - if (prop != NULL && RNA_property_boolean_get(op->ptr, prop)) { + if (confirm) { BKE_reportf(op->reports, RPT_INFO, "Successfully removed %d keyframes for keying set '%s'", @@ -2121,7 +2123,7 @@ static int delete_key_using_keying_set(bContext *C, wmOperator *op, KeyingSet *k /* send notifiers that keyframes have been changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL); } - else { + else if (confirm) { BKE_report(op->reports, RPT_WARNING, "Keying set failed to remove any keyframes"); } @@ -2289,6 +2291,8 @@ static int delete_key_v3d_without_keying_set(bContext *C, wmOperator *op) int selected_objects_success_len = 0; int success_multi = 0; + bool confirm = op->flag & OP_IS_INVOKE; + CTX_DATA_BEGIN (C, Object *, ob, selected_objects) { ID *id = &ob->id; int success = 0; @@ -2370,20 +2374,20 @@ static int delete_key_v3d_without_keying_set(bContext *C, wmOperator *op) /* report success (or failure) */ if (selected_objects_success_len) { - BKE_reportf(op->reports, - RPT_INFO, - "%d object(s) successfully had %d keyframes removed", - selected_objects_success_len, - success_multi); + if (confirm) { + BKE_reportf(op->reports, + RPT_INFO, + "%d object(s) successfully had %d keyframes removed", + selected_objects_success_len, + success_multi); + } + /* send updates */ + WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, NULL); } - else { + else if (confirm) { BKE_reportf( op->reports, RPT_ERROR, "No keyframes removed from %d object(s)", selected_objects_len); } - - /* send updates */ - WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, NULL); - return OPERATOR_FINISHED; } -- cgit v1.2.3