Merge branch 'blender-v3.6-release'
[blender-addons.git] / materials_utils / __init__.py
blob45f04c2c4c2ff43dd082edf98ba8bb2d0a107880
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Material Utilities v2.2.0-Beta
5 # Usage: Shift + Q in the 3D viewport
7 # Ported from 2.6/2.7 to 2.8x by
8 # Christopher Hindefjord (chrishinde) 2019
10 # ## Port based on 2010 version by MichaelW with some code added from latest 2.7x version
11 # ## Same code may be attributed to one of the following awesome people!
12 # (c) 2016 meta-androcto, parts based on work by Saidenka, lijenstina
13 # Materials Utils: by MichaleW, lijenstina,
14 # (some code thanks to: CoDEmanX, SynaGl0w, ideasman42)
15 # Link to base names: Sybren, Texture renamer: Yadoob
16 # ###
18 bl_info = {
19 "name": "Material Utilities",
20 "author": "MichaleW, ChrisHinde",
21 "version": (2, 2, 0),
22 "blender": (2, 80, 0),
23 "location": "View3D > Shift + Q key",
24 "description": "Menu of material tools (assign, select..) in the 3D View",
25 "warning": "Beta",
26 "doc_url": "{BLENDER_MANUAL_URL}/addons/materials/material_utils.html",
27 "category": "Material"
30 """
31 This script has several functions and operators, grouped for convenience:
33 * assign material:
34 offers the user a list of ALL the materials in the blend file and an
35 additional "new" entry the chosen material will be assigned to all the
36 selected objects in object mode.
38 in edit mode the selected polygons get the selected material applied.
40 if the user chose "new" the new material can be renamed using the
41 "last operator" section of the toolbox.
44 * select by material
45 in object mode this offers the user a menu of all materials in the blend
46 file any objects using the selected material will become selected, any
47 objects without the material will be removed from selection.
49 in edit mode: the menu offers only the materials attached to the current
50 object. It will select the polygons that use the material and deselect those
51 that do not.
53 * clean material slots
54 for all selected objects any empty material slots or material slots with
55 materials that are not used by the mesh polygons or splines will be removed.
57 * remove material slots
58 removes all material slots of the active (or selected) object(s).
60 * replace materials
61 lets your replace one material by another. Optionally for all objects in
62 the blend, otherwise for selected editable objects only. An additional
63 option allows you to update object selection, to indicate which objects
64 were affected and which not.
66 * set fake user
67 enable/disable fake user for materials. You can chose for which materials
68 it shall be set, materials of active / selected / objects in current scene
69 or used / unused / all materials.
71 """
73 if "bpy" in locals():
74 import importlib
75 if "enum_values" in locals():
76 importlib.reload(enum_values)
77 if "functions" in locals():
78 importlib.reload(functions)
79 if "operators" in locals():
80 importlib.reload(operators)
81 if "menues" in locals():
82 importlib.reload(menus)
83 if "preferences" in locals():
84 importlib.reload(preferences)
85 else:
86 from .enum_values import *
87 from .functions import *
88 from .operators import *
89 from .menus import *
90 from .preferences import *
92 import bpy
93 from bpy.props import (
94 PointerProperty,
96 from bpy.types import (
97 AddonPreferences,
98 PropertyGroup,
102 # All classes used by Material Utilities, that need to be registered
103 classes = (
104 VIEW3D_OT_materialutilities_assign_material_object,
105 VIEW3D_OT_materialutilities_assign_material_edit,
106 VIEW3D_OT_materialutilities_select_by_material_name,
107 VIEW3D_OT_materialutilities_copy_material_to_others,
109 VIEW3D_OT_materialutilities_clean_material_slots,
110 VIEW3D_OT_materialutilities_remove_material_slot,
111 VIEW3D_OT_materialutilities_remove_all_material_slots,
113 VIEW3D_OT_materialutilities_replace_material,
114 VIEW3D_OT_materialutilities_fake_user_set,
115 VIEW3D_OT_materialutilities_change_material_link,
117 MATERIAL_OT_materialutilities_merge_base_names,
118 MATERIAL_OT_materialutilities_join_objects,
119 MATERIAL_OT_materialutilities_auto_smooth_angle,
121 MATERIAL_OT_materialutilities_material_slot_move,
123 VIEW3D_MT_materialutilities_assign_material,
124 VIEW3D_MT_materialutilities_select_by_material,
126 VIEW3D_MT_materialutilities_clean_slots,
127 VIEW3D_MT_materialutilities_specials,
129 VIEW3D_MT_materialutilities_main,
131 VIEW3D_MT_materialutilities_preferences
135 # This allows you to right click on a button and link to the manual
136 def materialutilities_manual_map():
137 url_manual_prefix = "https://github.com/ChrisHinde/MaterialUtilities"
138 url_manual_map = []
139 #url_manual_mapping = ()
140 #("bpy.ops.view3d.materialutilities_*", ""),
141 #("bpy.ops.view3d.materialutilities_assign_material_edit", ""),
142 #("bpy.ops.view3d.materialutilities_select_by_material_name", ""),)
144 for cls in classes:
145 if issubclass(cls, bpy.types.Operator):
146 url_manual_map.append(("bpy.ops." + cls.bl_idname, ""))
148 url_manual_mapping = tuple(url_manual_map)
149 #print(url_manual_mapping)
150 return url_manual_prefix, url_manual_mapping
152 mu_classes_register, mu_classes_unregister = bpy.utils.register_classes_factory(classes)
155 def register():
156 """Register the classes of Material Utilities together with the default shortcut (Shift+Q)"""
157 mu_classes_register()
159 bpy.types.VIEW3D_MT_object_context_menu.append(materialutilities_specials_menu)
161 bpy.types.MATERIAL_MT_context_menu.prepend(materialutilities_menu_move)
162 bpy.types.MATERIAL_MT_context_menu.append(materialutilities_menu_functions)
164 kc = bpy.context.window_manager.keyconfigs.addon
165 if kc:
166 km = kc.keymaps.new(name = "3D View", space_type = "VIEW_3D")
167 kmi = km.keymap_items.new('wm.call_menu', 'Q', 'PRESS', ctrl = False, shift = True)
168 kmi.properties.name = VIEW3D_MT_materialutilities_main.bl_idname
170 bpy.utils.register_manual_map(materialutilities_manual_map)
173 def unregister():
174 """Unregister the classes of Material Utilities together with the default shortcut for the menu"""
176 bpy.utils.unregister_manual_map(materialutilities_manual_map)
178 bpy.types.VIEW3D_MT_object_context_menu.remove(materialutilities_specials_menu)
180 bpy.types.MATERIAL_MT_context_menu.remove(materialutilities_menu_move)
181 bpy.types.MATERIAL_MT_context_menu.remove(materialutilities_menu_functions)
183 kc = bpy.context.window_manager.keyconfigs.addon
184 if kc:
185 km = kc.keymaps["3D View"]
186 for kmi in km.keymap_items:
187 if kmi.idname == 'wm.call_menu':
188 if kmi.properties.name == VIEW3D_MT_materialutilities_main.bl_idname:
189 km.keymap_items.remove(kmi)
190 break
192 mu_classes_unregister()
194 if __name__ == "__main__":
195 register()