Anim Cupboard: Add Selection Sets to Animation Panel #81

Merged
Nick Alberelli merged 4 commits from feature/anim-cupboard-selection-set into main 2023-06-16 14:12:17 +02:00
2 changed files with 75 additions and 26 deletions

View File

@ -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)

View File

@ -0,0 +1,45 @@
import bpy
from addon_utils import check, paths
import sys
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':
is_enabled, is_loaded = check(mod_name)
sys.path.append(dir)
return is_enabled
return False
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 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
POSE_PT_selection_sets.draw(self, context)
registry = [
POSE_PT_selection_sets_view3d,
]