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