From 8f223527a2573621737f0bd643fcc91e4bf4c3a2 Mon Sep 17 00:00:00 2001 From: Blazer Date: Sat, 28 Dec 2024 04:50:52 -0600 Subject: [PATCH] Use Object.pose_library instead of Object.dspl.pose_library --- __init__.py | 29 +++++++---------------------- common.py | 21 +++++++++++++++------ gui.py | 14 ++++++++++---- operators.py | 15 ++++++++++----- 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/__init__.py b/__init__.py index e5c7d17..74c57d5 100644 --- a/__init__.py +++ b/__init__.py @@ -22,36 +22,23 @@ if _need_reload: operators = importlib.reload(operators) -class dsplObj(bpy.types.PropertyGroup): - pose_library: bpy.props.PointerProperty( - name="Active Pose Library", description="", - override={'LIBRARY_OVERRIDABLE'}, type=bpy.types.Action) - # update = common.poselib_update) - # , update = anim_layers.layer_name_update - - class dsplSettings(bpy.types.PropertyGroup): new_menu: bpy.props.BoolProperty( name="New Menu", description="Toggle New Menu", default=False) edit_mode: bpy.props.BoolProperty( name="Edit Mode", description="Toggle Edit Mode", default=False) -classes = (dsplObj, dsplSettings) +classes = dsplSettings def register(): from bpy.utils import register_class - for cls in classes: - register_class(cls) + register_class(dsplSettings) - # bpy.types.Armature.pose_library = bpy.props.PointerProperty( - # type=dsplObj, override={'LIBRARY_OVERRIDABLE'}) + bpy.types.Object.pose_library = bpy.props.PointerProperty( + name="Active Pose Library", description="", + type=bpy.types.Action, override={'LIBRARY_OVERRIDABLE'}) - # bpy.types.Object.pose_library = bpy.props.PointerProperty( - # type=bpy.types.Action, options={'LIBRARY_EDITABLE'}, override={'LIBRARY_OVERRIDABLE'}) - - bpy.types.Object.dspl = bpy.props.PointerProperty( - type=dsplObj, override={'LIBRARY_OVERRIDABLE'}) bpy.types.Scene.dsplSettings = bpy.props.PointerProperty( type=dsplSettings, override={'LIBRARY_OVERRIDABLE'}) @@ -59,12 +46,10 @@ def register(): operators.register() keymaps.register() -def unregister() -> None: +def unregister(): from bpy.utils import unregister_class - for cls in classes: - unregister_class(cls) + unregister_class(dsplSettings) - del bpy.types.Object.dspl del bpy.types.Scene.dsplSettings keymaps.unregister() diff --git a/common.py b/common.py index 324361d..627b842 100644 --- a/common.py +++ b/common.py @@ -14,18 +14,27 @@ def getArmatureObject(context): def getLegacyPoseLibrary(context): - arm = getArmatureObject(context) - return getattr(arm, "pose_library", None) + try: + arm = getArmatureObject(context) + return getattr(arm, "pose_library", None) + except: + pass def getArmatureAction(context): - arm = getArmatureObject(context) - return getattr(arm.animation_data, "action", None) + try: + arm = getArmatureObject(context) + return getattr(arm.animation_data, "action", None) + except: + pass def getDsplAction(context): - arm = getArmatureObject(context) - return getattr(arm.dspl, "pose_library", None) + try: + arm = getArmatureObject(context) + return getattr(arm.dspl, "pose_library", None) + except: + pass def getPoseLib(context): diff --git a/gui.py b/gui.py index 7ed96fe..3b09879 100644 --- a/gui.py +++ b/gui.py @@ -31,12 +31,18 @@ class DATA_PT_DSPLPanel(bpy.types.Panel): # Attach or create pose library pose_library_dspl = getDsplAction(context) pose_library_action = getArmatureAction(context) + pose_library_legacy = getLegacyPoseLibrary(context) - if pose_library_dspl or pose_library_action: + if pose_library_dspl or pose_library_action or pose_library_legacy: if pose_library_dspl and not pose_library_action: active_pose_library = pose_library_dspl armature_layout.template_ID( - arm_object.dspl, "pose_library", new="dspl.create_pose_library", unlink="dspl.unlink_pose_library") + arm_object, "pose_library", new="dspl.create_pose_library", unlink="dspl.unlink_pose_library") + + elif pose_library_legacy and not pose_library_dspl: + active_pose_library = pose_library_legacy + armature_layout.template_ID( + arm_object, "pose_library", new="dspl.create_pose_library", unlink="dspl.unlink_pose_library") elif pose_library_action and not pose_library_dspl: active_pose_library = pose_library_action @@ -51,7 +57,7 @@ class DATA_PT_DSPLPanel(bpy.types.Panel): elif pose_library_action and pose_library_dspl: armature_layout.template_ID( - arm_object.dspl, "pose_library", new="dspl.create_pose_library") + arm_object, "pose_library", new="dspl.create_pose_library") armature_layout.label(text="Double pose configuration!!") armature_layout.label(text="You should not proceed") armature_layout.operator( @@ -141,7 +147,7 @@ class DATA_PT_DSPLPanel(bpy.types.Panel): armature_layout.label( text="No Action or Pose Library detected") armature_layout.template_ID( - arm_object.dspl, "pose_library", new="dspl.create_pose_library") + arm_object, "pose_library", new="dspl.create_pose_library") else: armature_layout.label(text="No armature or parent selected") diff --git a/operators.py b/operators.py index f09a557..f7a8a7b 100644 --- a/operators.py +++ b/operators.py @@ -14,9 +14,9 @@ class DSPL_OT_CreatePoseLibrary(bpy.types.Operator): def execute(self, context): arm_object = getArmatureObject(context) - arm_object.dspl.pose_library = bpy.data.actions.new( + arm_object.pose_library = bpy.data.actions.new( name=arm_object.name + "_PoseLib") - arm_object.dspl.pose_library.use_fake_user = True + arm_object.pose_library.use_fake_user = True return {'FINISHED'} @@ -32,7 +32,7 @@ class DSPL_OT_ConvertPoseLibrary(bpy.types.Operator): def execute(self, context): arm_object = getArmatureObject(context) - arm_object.dspl.pose_library = arm_object.animation_data.action + arm_object.pose_library = arm_object.animation_data.action arm_object.animation_data.action = None return {'FINISHED'} @@ -399,8 +399,13 @@ class DSPL_OT_UnlinkPoseLibrary(bpy.types.Operator): arm_object = getArmatureObject(context) pose_library = getPoseLib(context) - arm_object.dspl.pose_library.name = "del_" + arm_object.dspl.pose_library.name - arm_object.dspl.pose_library = None + try: + arm_object.pose_library.use_fake_user = False + # if not arm_object.pose_library.name.startswith("del_"): + # arm_object.pose_library.name = "del_{}".format(arm_object.pose_library.name) + except: + pass + arm_object.pose_library = None return {'FINISHED'}