-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
150 lines (117 loc) · 4.81 KB
/
__init__.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ***** END GPL LICENSE BLOCK *****
bl_info = {
"name": "Key Ops: Toolkit",
"author": "Dan Gry, MACHIN3",
"version": (0, 1, 84),
"blender": (4, 0, 0),
"description": "Adds new tools, shortcuts and operations to Blender",
"category": "3D View"
}
#The following code is based on the MACHIN3 addon: MACHIN3tools
#Check out there awesome addons here: https://machin3.io/
#reload modules if the addon is updated, does not work for some reason :(
# def reload_modules(name):
# import bpy
# import os
# import importlib
# from . import classes_keymap_items
# global default_classes
# print("reloading", "default_classes")
# for cls in default_classes:
# bpy.utils.register_class(cls)
# utils_modules = sorted([name[:-3] for name in os.listdir(os.path.join(__path__[0], "utils")) if name.endswith('.py')])
# for module in utils_modules:
# impline = "from . utils import %s" % (module)
# print("reloading %s" % (".".join([name] + ['utils'] + [module])))
# exec(impline)
# importlib.reload(eval(module))
# for module in [classes_keymap_items]:
# print("reloading", module.__name__)
# importlib.reload(module)
# modules = []
# for label in classes_keymap_items.classes:
# entries = classes_keymap_items.classes[label]
# for entry in entries:
# path = entry[0].split('.')
# module = path.pop(-1)
# if (path, module) not in modules:
# modules.append((path, module))
# for path, module in modules:
# if path:
# impline = "from . %s import %s" % (".".join(path), module)
# else:
# impline = "from . import %s" % (module)
# print("reloading %s" % (".".join([name] + path + [module])))
# exec(impline)
# importlib.reload(eval(module))
from .addon_preferences import KeyOpsPreferences
from .operators.rebind import Rebind
from .operators.auto_smooth import AutoSmooth
#from .operators.extrude_edge_along_normals import ExtrudeEdgeAlongNormals
# if 'bpy' in locals():
# reload_modules(bl_info['name'])
import bpy
from .utils.register_extensions import get_extension, register_classes, unregister_classes, register_keymaps, unregister_keymaps
import time
default_classes = [
KeyOpsPreferences,
Rebind,
]
#only add AutoSmooth if the version is 4.1.0 or higher but not higher than 4.2.0 since its fixed in 4.2.0
if bpy.app.version >= (4, 1, 0) and bpy.app.version < (4, 2, 0):
default_classes.append(AutoSmooth)
def register():
debug = False
global classes, keymaps
global default_classes
if debug:
addon_start_time = time.time()
# Register default classes
if debug:
default_classes_start_time = time.time()
for cls in default_classes:
bpy.utils.register_class(cls)
if debug:
print(f"registering default classes took {time.time() - default_classes_start_time:.4f} seconds")
# Get extension classes and keymaps
if debug:
get_extension_time = time.time()
extension_classlists, extension_keylists = get_extension()
if debug:
print(f"get_extension() took {time.time() - get_extension_time:.4f} seconds")
# Register extension classes
if debug:
register_classes_time = time.time()
classes = register_classes(extension_classlists)
if debug:
print(f"register_classes() took {time.time() - register_classes_time:.4f} seconds")
# Register extension keymaps
if debug:
register_keymaps_time = time.time()
keymaps = register_keymaps(extension_keylists)
if debug:
print(f"register_keymaps() took {time.time() - register_keymaps_time:.4f} seconds")
print(f"{bl_info['name']} addon registered in {time.time() - addon_start_time:.4f} seconds")
# #print all addons names that are enabled
# for addon in bpy.context.preferences.addons:
# print(addon.module)
def unregister():
for cls in default_classes:
bpy.utils.unregister_class(cls)
global classes, keymaps
unregister_keymaps(keymaps)
unregister_classes(classes)
classes, keymaps = None, None