-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path__init__.py
More file actions
81 lines (68 loc) · 2.24 KB
/
Copy path__init__.py
File metadata and controls
81 lines (68 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# MetsTools addon for Blender
# Copyright (C) 2019 Demeter Dzadik
bl_info = {
"name": "MetsTools",
"author": "Demeter Dzadik",
"version": (2, 4),
"blender": (3, 0, 0),
"location": "View3D > Search",
"description": "Random collection of tools I built for myself",
"category": "Rigging",
"doc_url": "https://github.com/Mets3D/mets_tools/blob/master/docs/README.md",
"tracker_url": "https://github.com/Mets3D/mets_tools/issues/new",
}
from typing import List
import importlib
from bpy.utils import register_class, unregister_class
from . import (
armature_apply_scale,
armature_constraint_vertex_parent,
refresh_drivers,
create_transform_constraint,
setup_action_constraints,
vgroup_merge,
remove_empty_shapekeys,
mark_non_deform_bones,
prefs,
)
# Each module is expected to have a register() and unregister() function.
modules = [
armature_apply_scale,
armature_constraint_vertex_parent,
refresh_drivers,
create_transform_constraint,
setup_action_constraints,
vgroup_merge,
remove_empty_shapekeys,
mark_non_deform_bones,
prefs,
]
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
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"ERROR: MetsTools failed to {un}register class: {c.__name__}"
)
print(e)
if hasattr(m, 'modules'):
register_unregister_modules(m.modules, register)
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)