From ad870ed3dc24a5bfe9acdd948add2ad6ec5146bb Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 7 Jun 2023 10:08:41 -0400 Subject: [PATCH 1/3] Blender Kitsu: Fix Getting Action Names Safely - Use .get() function to find existing actions - Only create new action if none exists --- scripts-blender/addons/blender_kitsu/anim/ops.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index 609bc78a..acf76c09 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -115,6 +115,12 @@ class KITSU_OT_anim_check_action_names(bpy.types.Operator): @classmethod def poll(cls, context: bpy.types.Context) -> bool: return bool(cache.shot_active_get()) + + def get_action(self, action_name:str): + if bpy.data.actions.get(action_name): + return bpy.data.actions.get(action_name) + else: + return bpy.data.actions.new(action_name) def execute(self, context: bpy.types.Context) -> Set[str]: active_shot = cache.shot_active_get() @@ -140,9 +146,8 @@ class KITSU_OT_anim_check_action_names(bpy.types.Operator): # Cerate Action if None Exists if obj.animation_data is None or obj.animation_data.action is None: base_name = obj.name.split(addon_prefs.shot_builder_armature_prefix)[-1] - new_action = bpy.data.actions.new( - f"{addon_prefs.shot_builder_action_prefix}{base_name}.{active_shot.name}.v001" - ) + action_name = f"{addon_prefs.shot_builder_action_prefix}{base_name}.{active_shot.name}.v001" + new_action = self.get_action(action_name) new_action.use_fake_user = True obj.animation_data_create() obj.animation_data.action = new_action -- 2.30.2 From 69a4f03415e755a776e705ed879aa3d3d24b5355 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 7 Jun 2023 10:20:51 -0400 Subject: [PATCH 2/3] Blender Kitsu: Add reporting for newly created actions --- scripts-blender/addons/blender_kitsu/anim/ops.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index acf76c09..78ab2f9b 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -108,7 +108,9 @@ class KITSU_OT_anim_check_action_names(bpy.types.Operator): "if they follow the Blender Studio naming convention" ) wrong: List[Tuple[bpy.types.Action, str]] = [] + created: List[Tuple[bpy.types.Action, str]] = [] cleanup_empty_actions: bpy.props.BoolProperty(name="Delete Empty Action Data-Blocks", default=False, description="Remove any empty action data-blocks, actions that have 0 Fcurves/Keyframes") + # List of tuples that contains the action on index 0 with the wrong name # and the name it should have on index 1. @@ -120,7 +122,9 @@ class KITSU_OT_anim_check_action_names(bpy.types.Operator): if bpy.data.actions.get(action_name): return bpy.data.actions.get(action_name) else: - return bpy.data.actions.new(action_name) + new_action = bpy.data.actions.new(action_name) + self.created.append(new_action) + return new_action def execute(self, context: bpy.types.Context) -> Set[str]: active_shot = cache.shot_active_get() @@ -178,7 +182,9 @@ class KITSU_OT_anim_check_action_names(bpy.types.Operator): report_str += f" | Removed Empty Actions: {len(removed)}" if failed: report_state = "WARNING" - report_str += f" | Failed: {len(failed)}" + report_str += f" | Rename Failed: {len(failed)}" + if len(self.created) != 0: + report_str += f" | Created Actions: {len(self.created)}" -- 2.30.2 From 7df533fa7ae937f1c3f213788241188136f7767f Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 7 Jun 2023 10:53:48 -0400 Subject: [PATCH 3/3] Blender Kitsu: Fix Check Action Names reporting - Clear list contents on invoke - Set created prop to a list of strings --- scripts-blender/addons/blender_kitsu/anim/ops.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index 78ab2f9b..e4637380 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -108,7 +108,7 @@ class KITSU_OT_anim_check_action_names(bpy.types.Operator): "if they follow the Blender Studio naming convention" ) wrong: List[Tuple[bpy.types.Action, str]] = [] - created: List[Tuple[bpy.types.Action, str]] = [] + created: List[bpy.types.Action] = [] cleanup_empty_actions: bpy.props.BoolProperty(name="Delete Empty Action Data-Blocks", default=False, description="Remove any empty action data-blocks, actions that have 0 Fcurves/Keyframes") # List of tuples that contains the action on index 0 with the wrong name @@ -201,6 +201,7 @@ class KITSU_OT_anim_check_action_names(bpy.types.Operator): def invoke(self, context, event): shot_active = cache.shot_active_get() self.wrong.clear() + self.created.clear() no_action = [] correct = [] -- 2.30.2