[Blender_Kitsu] Add Operators to cleanup Animation Files #38

Merged
Nick Alberelli merged 12 commits from feature/enforce_naming into main 2023-05-09 17:12:20 +02:00
Showing only changes of commit e2a3476d7e - Show all commits

View File

@ -117,10 +117,25 @@ class KITSU_OT_anim_check_action_names(bpy.types.Operator):
return bool(cache.shot_active_get())
def execute(self, context: bpy.types.Context) -> Set[str]:
active_shot = cache.shot_active_get()
addon_prefs = bpy.context.preferences.addons["blender_kitsu"].preferences
existing_action_names = [a.name for a in bpy.data.actions]
failed = []
succeeded = []
for obj in [obj for obj in bpy.data.objects if obj.type == "ARMATURE"]:
# 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")
new_action.use_fake_user = True
obj.animation_data_create()
obj.animation_data.action = new_action
obj.animation_data.action.name = f"{addon_prefs.shot_builder_action_prefix}{base_name}.{active_shot.name}.v001"
# Rename actions.
for action, name in self.wrong:
if name in existing_action_names:
@ -278,8 +293,6 @@ class KITSU_OT_anim_enforce_naming_convention(bpy.types.Operator):
def execute(self, context:bpy.types.Context):
shot_base_name = bpy.path.basename(bpy.data.filepath).replace(".anim.blend","")
active_shot = cache.shot_active_get()
addon_prefs = bpy.context.preferences.addons["blender_kitsu"].preferences
scene_col = context.scene.collection
anim_suffix = "anim.output"
@ -308,17 +321,6 @@ class KITSU_OT_anim_enforce_naming_convention(bpy.types.Operator):
# Rename Actions
if self.rename_actions:
for obj in [obj for obj in bpy.data.objects if obj.type == "ARMATURE"]:
base_name = obj.name.split(
addon_prefs.shot_builder_armature_prefix)[-1]
# Cerate Action if None Exists
if obj.animation_data is None or obj.animation_data.action is None:
new_action = bpy.data.actions.new(
f"{addon_prefs.shot_builder_action_prefix}{base_name}.{active_shot.name}.v001")
new_action.use_fake_user = True
obj.animation_data_create()
obj.animation_data.action = new_action
obj.animation_data.action.name = f"{addon_prefs.shot_builder_action_prefix}{base_name}.{active_shot.name}.v001"
bpy.ops.kitsu.anim_check_action_names()
self.report(
{"INFO"},