From 8f2efc1caaf47957c97676f4b134d62d1df17fec Mon Sep 17 00:00:00 2001 From: NickTiny Date: Wed, 14 Jun 2023 18:14:07 -0400 Subject: [PATCH 1/4] Anim_Cupboard: Add Selection Sets to Animation Panel - Add Selection Sets to Animation Panel - Register Bone_Selection_Sets.py in __init__.py - Enforce Black Formatting on modified files --- .../addons/anim_cupboard/__init__.py | 56 +++++++------ .../anim_cupboard/bone_selection_sets.py | 84 +++++++++++++++++++ 2 files changed, 114 insertions(+), 26 deletions(-) create mode 100644 scripts-blender/addons/anim_cupboard/bone_selection_sets.py diff --git a/scripts-blender/addons/anim_cupboard/__init__.py b/scripts-blender/addons/anim_cupboard/__init__.py index 4b5a53a3..2f29fec5 100644 --- a/scripts-blender/addons/anim_cupboard/__init__.py +++ b/scripts-blender/addons/anim_cupboard/__init__.py @@ -8,13 +8,14 @@ from .operators import lock_curves from .operators import bake_anim_across_armatures from . import easy_constraints from . import warn_about_broken_libraries +from . import bone_selection_sets bl_info = { - 'name' : "Animation Cupboard", + 'name': "Animation Cupboard", 'author': "Demeter Dzadik", "version": (0, 0, 2), - 'blender' : (3, 2, 0), - 'description' : "Tools to improve animation workflows", + 'blender': (3, 2, 0), + 'description': "Tools to improve animation workflows", 'location': "Various", 'category': 'Animation', # 'doc_url' : "https://gitlab.com/blender/CloudRig/", @@ -25,39 +26,42 @@ modules = ( lock_curves, bake_anim_across_armatures, easy_constraints, - warn_about_broken_libraries + warn_about_broken_libraries, + bone_selection_sets, ) def register_unregister_modules(modules: List, register: bool): - """Recursively register or unregister modules by looking for either - un/register() functions or lists named `registry` which should be a list of - registerable classes. - """ - register_func = register_class if register else unregister_class + """Recursively register or unregister modules by looking for either + un/register() functions or lists named `registry` which should be a list of + registerable classes. + """ + register_func = register_class if register else unregister_class - for m in modules: - if register: - importlib.reload(m) - if hasattr(m, 'registry'): - for c in m.registry: - try: - register_func(c) - except Exception as e: - un = 'un' if not register else '' - print(f"Warning: Failed to {un}register class: {c.__name__}") - print(e) + for m in modules: + if register: + importlib.reload(m) + if hasattr(m, 'registry'): + for c in m.registry: + try: + register_func(c) + except Exception as e: + un = 'un' if not register else '' + print(f"Warning: Failed to {un}register class: {c.__name__}") + print(e) - if hasattr(m, 'modules'): - register_unregister_modules(m.modules, register) + if hasattr(m, 'modules'): + register_unregister_modules(m.modules, register) + + if register and hasattr(m, 'register'): + m.register() + elif hasattr(m, 'unregister'): + m.unregister() - if register and hasattr(m, 'register'): - m.register() - elif hasattr(m, 'unregister'): - m.unregister() def register(): register_unregister_modules(modules, True) + def unregister(): register_unregister_modules(modules, False) diff --git a/scripts-blender/addons/anim_cupboard/bone_selection_sets.py b/scripts-blender/addons/anim_cupboard/bone_selection_sets.py new file mode 100644 index 00000000..f23c931f --- /dev/null +++ b/scripts-blender/addons/anim_cupboard/bone_selection_sets.py @@ -0,0 +1,84 @@ +import bpy +from addon_utils import check, paths, enable + + +import sys + + +# RELEASE SCRIPTS: official scripts distributed in Blender releases + +addon_enabled = False +paths_list = paths() +addon_list = [] +for path in paths_list: + for mod_name, mod_path in bpy.path.module_names(path): + if mod_name == 'bone_selection_sets': + is_enabled, is_loaded = check(mod_name) + addon_enabled = is_enabled + break + + +class POSE_PT_selection_sets_view3d(bpy.types.Panel): + bl_label = "Selection Sets" + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_category = 'Animation' + + @classmethod + def poll(cls, context): + return context.mode == 'POSE' and context.active_pose_bone + + def draw(self, context): + layout = self.layout + if not addon_enabled: + layout.label(text="Addon 'Bone Selection Sets' not Enabled", icon="ERROR") + return + + arm = context.object + + row = layout.row() + row.enabled = context.mode == 'POSE' + + # UI list + rows = 4 if len(arm.selection_sets) > 0 else 1 + row.template_list( + "POSE_UL_selection_set", + "", # type and unique id + arm, + "selection_sets", # pointer to the CollectionProperty + arm, + "active_selection_set", # pointer to the active identifier + rows=rows, + ) + + # add/remove/specials UI list Menu + col = row.column(align=True) + col.operator("pose.selection_set_add", icon='ADD', text="") + col.operator("pose.selection_set_remove", icon='REMOVE', text="") + col.menu("POSE_MT_selection_sets_context_menu", icon='DOWNARROW_HLT', text="") + + # move up/down arrows + if len(arm.selection_sets) > 0: + col.separator() + col.operator( + "pose.selection_set_move", icon='TRIA_UP', text="" + ).direction = 'UP' + col.operator( + "pose.selection_set_move", icon='TRIA_DOWN', text="" + ).direction = 'DOWN' + + # buttons + row = layout.row() + + sub = row.row(align=True) + sub.operator("pose.selection_set_assign", text="Assign") + sub.operator("pose.selection_set_unassign", text="Remove") + + sub = row.row(align=True) + sub.operator("pose.selection_set_select", text="Select") + sub.operator("pose.selection_set_deselect", text="Deselect") + + +registry = [ + POSE_PT_selection_sets_view3d, +] -- 2.30.2 From e4d3636e0dc692192b8049c9d55171c7f763293b Mon Sep 17 00:00:00 2001 From: NickTiny Date: Wed, 14 Jun 2023 18:39:09 -0400 Subject: [PATCH 2/4] Anim_Cupboard: Check Dependant Addon with Function --- .../anim_cupboard/bone_selection_sets.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/scripts-blender/addons/anim_cupboard/bone_selection_sets.py b/scripts-blender/addons/anim_cupboard/bone_selection_sets.py index f23c931f..645b42bc 100644 --- a/scripts-blender/addons/anim_cupboard/bone_selection_sets.py +++ b/scripts-blender/addons/anim_cupboard/bone_selection_sets.py @@ -1,5 +1,5 @@ import bpy -from addon_utils import check, paths, enable +from addon_utils import check, paths import sys @@ -8,14 +8,15 @@ import sys # RELEASE SCRIPTS: official scripts distributed in Blender releases addon_enabled = False -paths_list = paths() -addon_list = [] -for path in paths_list: - for mod_name, mod_path in bpy.path.module_names(path): - if mod_name == 'bone_selection_sets': - is_enabled, is_loaded = check(mod_name) - addon_enabled = is_enabled - break + + +def check_addon_enabled(): + for path in paths(): + for mod_name, mod_path in bpy.path.module_names(path): + if mod_name == 'bone_selection_sets': + is_enabled, is_loaded = check(mod_name) + return is_enabled + return False class POSE_PT_selection_sets_view3d(bpy.types.Panel): @@ -30,7 +31,7 @@ class POSE_PT_selection_sets_view3d(bpy.types.Panel): def draw(self, context): layout = self.layout - if not addon_enabled: + if not check_addon_enabled(): layout.label(text="Addon 'Bone Selection Sets' not Enabled", icon="ERROR") return -- 2.30.2 From ed74d71e59f441bbf5e35b3027dbd4d3cb0ab252 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 15 Jun 2023 15:23:41 -0400 Subject: [PATCH 3/4] Anim Cupboard: Call Selection Sets Draw from Dependant Addon - Re-use existing selection sets draw function - Report to user if addon is not found - Remove unrelated comment --- .../anim_cupboard/bone_selection_sets.py | 49 ++----------------- 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/scripts-blender/addons/anim_cupboard/bone_selection_sets.py b/scripts-blender/addons/anim_cupboard/bone_selection_sets.py index 645b42bc..ba1a222f 100644 --- a/scripts-blender/addons/anim_cupboard/bone_selection_sets.py +++ b/scripts-blender/addons/anim_cupboard/bone_selection_sets.py @@ -5,8 +5,6 @@ from addon_utils import check, paths import sys -# RELEASE SCRIPTS: official scripts distributed in Blender releases - addon_enabled = False @@ -15,6 +13,7 @@ def check_addon_enabled(): for mod_name, mod_path in bpy.path.module_names(path): if mod_name == 'bone_selection_sets': is_enabled, is_loaded = check(mod_name) + sys.path.append(dir) return is_enabled return False @@ -34,50 +33,10 @@ class POSE_PT_selection_sets_view3d(bpy.types.Panel): if not check_addon_enabled(): layout.label(text="Addon 'Bone Selection Sets' not Enabled", icon="ERROR") return + import bone_selection_sets + from bone_selection_sets import POSE_PT_selection_sets - arm = context.object - - row = layout.row() - row.enabled = context.mode == 'POSE' - - # UI list - rows = 4 if len(arm.selection_sets) > 0 else 1 - row.template_list( - "POSE_UL_selection_set", - "", # type and unique id - arm, - "selection_sets", # pointer to the CollectionProperty - arm, - "active_selection_set", # pointer to the active identifier - rows=rows, - ) - - # add/remove/specials UI list Menu - col = row.column(align=True) - col.operator("pose.selection_set_add", icon='ADD', text="") - col.operator("pose.selection_set_remove", icon='REMOVE', text="") - col.menu("POSE_MT_selection_sets_context_menu", icon='DOWNARROW_HLT', text="") - - # move up/down arrows - if len(arm.selection_sets) > 0: - col.separator() - col.operator( - "pose.selection_set_move", icon='TRIA_UP', text="" - ).direction = 'UP' - col.operator( - "pose.selection_set_move", icon='TRIA_DOWN', text="" - ).direction = 'DOWN' - - # buttons - row = layout.row() - - sub = row.row(align=True) - sub.operator("pose.selection_set_assign", text="Assign") - sub.operator("pose.selection_set_unassign", text="Remove") - - sub = row.row(align=True) - sub.operator("pose.selection_set_select", text="Select") - sub.operator("pose.selection_set_deselect", text="Deselect") + POSE_PT_selection_sets.draw(self, context) registry = [ -- 2.30.2 From 45a133257c788b4d0c136a5d5ce9ffdc38b79378 Mon Sep 17 00:00:00 2001 From: NickTiny Date: Thu, 15 Jun 2023 23:20:36 -0400 Subject: [PATCH 4/4] Anim Cupboard: Add Comment --- scripts-blender/addons/anim_cupboard/bone_selection_sets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts-blender/addons/anim_cupboard/bone_selection_sets.py b/scripts-blender/addons/anim_cupboard/bone_selection_sets.py index ba1a222f..b872926e 100644 --- a/scripts-blender/addons/anim_cupboard/bone_selection_sets.py +++ b/scripts-blender/addons/anim_cupboard/bone_selection_sets.py @@ -9,6 +9,7 @@ addon_enabled = False def check_addon_enabled(): + # Adapted from https://blenderartists.org/t/check-if-add-on-is-enabled-using-python/522226/2 for path in paths(): for mod_name, mod_path in bpy.path.module_names(path): if mod_name == 'bone_selection_sets': -- 2.30.2