forked from ChrisHinde/MaterialUtilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
216 lines (169 loc) · 7.48 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Material Utilities v2.4.0
#
# Usage: Shift + Q in the 3D viewport
#
# Ported from 2.6/2.7 to 2.8x by
# Christopher Hindefjord (chrishinde) 2019
#
# ## Port based on 2010 version by MichaelW with some code added from latest 2.7x version
# ## Same code may be attributed to one of the following awesome people!
# (c) 2016 meta-androcto, parts based on work by Saidenka, lijenstina
# Materials Utils: by MichaleW, lijenstina,
# (some code thanks to: CoDEmanX, SynaGl0w, ideasman42)
# Link to base names: Sybren, Texture renamer: Yadoob
# ###
#
#
# ##### 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 2
# 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "Material Utilities",
"author": "MichaleW, ChrisHinde",
"version": (2, 4, 1),
"blender": (2, 80, 0),
"location": "View3D > Shift + Q key",
"description": "Menu of material tools (assign, select..) in the 3D View",
"doc_url": "{BLENDER_MANUAL_URL}/addons/materials/material_utils.html",
"category": "Material"
}
"""
This script has several functions and operators, grouped for convenience:
* assign material:
offers the user a list of ALL the materials in the blend file and an
additional "new" entry the chosen material will be assigned to all the
selected objects in object mode.
in edit mode the selected polygons get the selected material applied.
if the user chose "new" the new material can be renamed using the
"last operator" section of the toolbox.
* select by material
in object mode this offers the user a menu of all materials in the blend
file any objects using the selected material will become selected, any
objects without the material will be removed from selection.
in edit mode: the menu offers only the materials attached to the current
object. It will select the polygons that use the material and deselect those
that do not.
* clean material slots
for all selected objects any empty material slots or material slots with
materials that are not used by the mesh polygons or splines will be removed.
* remove material slots
removes all material slots of the active (or selected) object(s).
* replace materials
lets your replace one material by another. Optionally for all objects in
the blend, otherwise for selected editable objects only. An additional
option allows you to update object selection, to indicate which objects
were affected and which not.
* set fake user
enable/disable fake user for materials. You can chose for which materials
it shall be set, materials of active / selected / objects in current scene
or used / unused / all materials.
"""
if "bpy" in locals():
import importlib
if "enum_values" in locals():
importlib.reload(enum_values)
if "functions" in locals():
importlib.reload(functions)
if "operators" in locals():
importlib.reload(operators)
if "menues" in locals():
importlib.reload(menus)
if "preferences" in locals():
importlib.reload(preferences)
else:
from .enum_values import *
from .functions import *
from .operators import *
from .menus import *
from .preferences import *
import bpy
from bpy.props import (
PointerProperty,
)
from bpy.types import (
AddonPreferences,
PropertyGroup,
)
# All classes used by Material Utilities, that need to be registred
classes = (
VIEW3D_OT_materialutilities_assign_material_object,
VIEW3D_OT_materialutilities_assign_material_edit,
VIEW3D_OT_materialutilities_select_by_material_name,
VIEW3D_OT_materialutilities_copy_material_to_others,
VIEW3D_OT_materialutilities_clean_material_slots,
VIEW3D_OT_materialutilities_remove_material_slot,
VIEW3D_OT_materialutilities_remove_all_material_slots,
VIEW3D_OT_materialutilities_replace_material,
VIEW3D_OT_materialutilities_fake_user_set,
VIEW3D_OT_materialutilities_change_material_link,
MATERIAL_OT_materialutilities_merge_base_names,
MATERIAL_OT_materialutilities_join_objects,
MATERIAL_OT_materialutilities_auto_smooth_angle,
MATERIAL_OT_materialutilities_material_slot_move,
VIEW3D_MT_materialutilities_assign_material,
VIEW3D_MT_materialutilities_select_by_material,
VIEW3D_MT_materialutilities_clean_slots,
VIEW3D_MT_materialutilities_specials,
VIEW3D_MT_materialutilities_main,
VIEW3D_MT_materialutilities_preferences
)
# This allows you to right click on a button and link to the manual
def materialutilities_manual_map():
url_manual_prefix = "https://github.com/ChrisHinde/MaterialUtilities"
url_manual_map = []
for cls in classes:
if issubclass(cls, bpy.types.Operator):
url_manual_map.append(("bpy.ops." + cls.bl_idname, ""))
url_manual_mapping = tuple(url_manual_map)
#print(url_manual_mapping)
return url_manual_prefix, url_manual_mapping
mu_classes_register, mu_classes_unregister = bpy.utils.register_classes_factory(classes)
def register():
"""Register the classes of Material Utilities together with the default shortcut (Shift+Q)"""
mu_classes_register()
bpy.types.VIEW3D_MT_object_context_menu.append(materialutilities_specials_menu)
bpy.types.MATERIAL_MT_context_menu.prepend(materialutilities_menu_move)
bpy.types.MATERIAL_MT_context_menu.append(materialutilities_menu_functions)
kc = bpy.context.window_manager.keyconfigs.addon
if kc:
km = kc.keymaps.new(name = "3D View", space_type = "VIEW_3D")
kmi = km.keymap_items.new('wm.call_menu', 'Q', 'PRESS', ctrl = False, shift = True)
kmi.properties.name = VIEW3D_MT_materialutilities_main.bl_idname
bpy.utils.register_manual_map(materialutilities_manual_map)
def unregister():
"""Unregister the classes of Material Utilities together with the default shortcut for the menu"""
bpy.utils.unregister_manual_map(materialutilities_manual_map)
bpy.types.VIEW3D_MT_object_context_menu.remove(materialutilities_specials_menu)
bpy.types.MATERIAL_MT_context_menu.remove(materialutilities_menu_move)
#kc = bpy.context.window_manager.keyconfigs.addon
bpy.types.MATERIAL_MT_context_menu.remove(materialutilities_menu_functions)
keyconfigs = bpy.context.window_manager.keyconfigs
defaultmap = keyconfigs.get("blender").keymaps
addonmap = keyconfigs.get("blender addon").keymaps
km = addonmap["3D View"]
for kmi in km.keymap_items:
if kmi.idname == "wm.call_menu":
if kmi.properties.name == VIEW3D_MT_materialutilities_main.bl_idname:
km.keymap_items.remove(kmi)
km = defaultmap["3D View"]
for kmi in km.keymap_items:
if kmi.idname == "wm.call_menu":
if kmi.properties.name == VIEW3D_MT_materialutilities_main.bl_idname:
km.keymap_items.remove(kmi)
mu_classes_unregister()
if __name__ == "__main__":
register()