From baa581415c7ed23d7c45ef873631748135672683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 7 Apr 2022 11:21:59 +0200 Subject: Pose Library: better support for legacy pose libraries Rename "old-style pose library" to "legacy pose library" for consistency with other code, and add pose library conversion operator for use in the "Pose Library (Legacy)" Armature properties panel. --- pose_library/operators.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/pose_library/operators.py b/pose_library/operators.py index 1e8a1b5c..a1cccd2c 100644 --- a/pose_library/operators.py +++ b/pose_library/operators.py @@ -435,7 +435,7 @@ class POSELIB_OT_apply_pose_asset_for_keymap(Operator): class POSELIB_OT_convert_old_poselib(Operator): bl_idname = "poselib.convert_old_poselib" - bl_label = "Convert Old-Style Pose Library" + bl_label = "Convert Legacy Pose Library" bl_description = "Create a pose asset for each pose marker in the current action" bl_options = {"REGISTER", "UNDO"} @@ -446,7 +446,7 @@ class POSELIB_OT_convert_old_poselib(Operator): cls.poll_message_set("Active object has no Action") return False if not action.pose_markers: - cls.poll_message_set("Action %r is not a old-style pose library" % action.name) + cls.poll_message_set("Action %r is not a legacy pose library" % action.name) return False return True @@ -464,11 +464,46 @@ class POSELIB_OT_convert_old_poselib(Operator): return {'FINISHED'} +class POSELIB_OT_convert_old_object_poselib(Operator): + bl_idname = "poselib.convert_old_object_poselib" + bl_label = "Convert Legacy Pose Library" + bl_description = "Create a pose asset for each pose marker in this legacy pose library data-block" + + # Mark this one as "internal", as it converts `context.object.pose_library` + # instead of its current animation Action. + bl_options = {"REGISTER", "UNDO", "INTERNAL"} + + @classmethod + def poll(cls, context: Context) -> bool: + action = context.object and context.object.pose_library + if not action: + cls.poll_message_set("Active object has no pose library Action") + return False + if not action.pose_markers: + cls.poll_message_set("Action %r is not a legacy pose library" % action.name) + return False + return True + + def execute(self, context: Context) -> Set[str]: + from . import conversion + + old_poselib = context.object.pose_library + new_actions = conversion.convert_old_poselib(old_poselib) + + if not new_actions: + self.report({'ERROR'}, "Unable to convert to pose assets") + return {'CANCELLED'} + + self.report({'INFO'}, "Converted %d poses to pose assets" % len(new_actions)) + return {'FINISHED'} + + classes = ( ASSET_OT_assign_action, POSELIB_OT_apply_pose_asset_for_keymap, POSELIB_OT_blend_pose_asset_for_keymap, POSELIB_OT_convert_old_poselib, + POSELIB_OT_convert_old_object_poselib, POSELIB_OT_copy_as_asset, POSELIB_OT_create_pose_asset, POSELIB_OT_paste_asset, -- cgit v1.2.3