diff options
author | Gaia Clary <gaiaclary> | 2021-09-28 15:07:02 +0300 |
---|---|---|
committer | Gaia Clary <gaia.clary@machinimatrix.org> | 2021-09-29 14:09:17 +0300 |
commit | 78b9a8c7b993991c22ac2bd1ffbfaf1d896e4431 (patch) | |
tree | 801d8318c5d650edb262b2192fb6b61f1670db0f /source/blender/editors/animation | |
parent | 6351c73b758d1b2f4d6b9e85c9bf07074b369be5 (diff) |
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
Diffstat (limited to 'source/blender/editors/animation')
-rw-r--r-- | source/blender/editors/animation/keyframing.c | 30 |
1 files 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; } |