[Bf-extensions-cvs] [4fa93f6e] master: materials_utils: add search and preferences T67990

meta-androcto noreply at git.blender.org
Sat Aug 17 02:19:24 CEST 2019


Commit: 4fa93f6eb1b63c2662190336d685358c34209cb2
Author: meta-androcto
Date:   Sat Aug 17 10:19:02 2019 +1000
Branches: master
https://developer.blender.org/rBA4fa93f6eb1b63c2662190336d685358c34209cb2

materials_utils: add search and preferences T67990

===================================================================

M	materials_utils/__init__.py
M	materials_utils/enum_values.py
M	materials_utils/functions.py
M	materials_utils/menus.py
M	materials_utils/operators.py
A	materials_utils/preferences.py

===================================================================

diff --git a/materials_utils/__init__.py b/materials_utils/__init__.py
index 40f976d7..2a4561f4 100644
--- a/materials_utils/__init__.py
+++ b/materials_utils/__init__.py
@@ -1,3 +1,19 @@
+# Material Utilities v2.2.0-Beta
+#
+#  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
@@ -15,22 +31,15 @@
 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 # ##### END GPL LICENSE BLOCK #####
- 
-#  Based on 2010 version by MichaelW
-#  (c) 2016 meta-androcto, parts based on work by Saidenka, lijenstina
-#  Materials Utils: by MichaleW, meta-androcto, lijenstina,
-#  (some code thanks to: CoDEmanX, SynaGl0w, ideasman42)
-#  Link to base names: Sybren, Texture renamer: Yadoob
-#  Ported from 2.6/2.7 to 2.8x by Christopher Hindefjord (chrishinde) 2019
 
 bl_info = {
-    "name": "Material Utils",
+    "name": "Material Utilities",
     "author": "MichaleW, ChrisHinde",
-    "version": (1, 0, 6),
+    "version": (2, 2, 0),
     "blender": (2, 80, 0),
     "location": "View3D > Shift + Q key",
     "description": "Menu of material tools (assign, select..) in the 3D View",
-    "warning": "",
+    "warning": "Beta",
     "wiki_url": "https://github.com/ChrisHinde/MaterialUtilities",
     "category": "Material"
 }
@@ -78,13 +87,34 @@ This script has several functions and operators, grouped for convenience:
 
 """
 
+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,
+    )
 
-from .enum_values import *
-from .functions import *
-from .operators import *
-from .menus import *
 
 # All classes used by Material Utilities, that need to be registred
 classes = (
@@ -102,6 +132,8 @@ classes = (
     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,
 
@@ -112,12 +144,13 @@ classes = (
     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():
-    print("ManMap")
     url_manual_prefix = "https://github.com/ChrisHinde/MaterialUtilities"
     url_manual_map = []
     #url_manual_mapping = ()
@@ -156,7 +189,6 @@ def register():
 
 def unregister():
     """Unregister the classes of Material Utilities together with the default shortcut for the menu"""
-    mu_classes_unregister()
 
     bpy.utils.unregister_manual_map(materialutilities_manual_map)
 
@@ -174,6 +206,7 @@ def unregister():
                     km.keymap_items.remove(kmi)
                     break
 
+    mu_classes_unregister()
 
 if __name__ == "__main__":
     register()
diff --git a/materials_utils/enum_values.py b/materials_utils/enum_values.py
index f7f8f65b..2f257400 100644
--- a/materials_utils/enum_values.py
+++ b/materials_utils/enum_values.py
@@ -4,21 +4,33 @@ import bpy
 mu_override_type_enums = [
     ('OVERRIDE_ALL', "Override all assigned slots",
         "Remove any current material slots, and assign the current material"),
+    ('OVERRIDE_CURRENT', 'Assign material to currently selected slot',
+        'Only assign the material to the material slot that\'s currently selected'),
     ('OVERRIDE_SLOTS', 'Assign material to each slot',
         'Keep the material slots, but assign the selected material in each slot'),
     ('APPEND_MATERIAL', 'Append Material',
         'Add the material in a new slot, and assign it to the whole object')
 ]
 
+mu_clean_slots_enums = (('ACTIVE', "Active object", "Materials of active object only"),
+                        ('SELECTED', "Selected objects", "Materials of selected objects"),
+                        ('SCENE', "Scene objects", "Materials of objects in current scene"),
+                        ('ALL', "All", "All materials in this blend file"))
+
+mu_affect_enums = (('ACTIVE', "Active object", "Affect the active object only"),
+                   ('SELECTED', "Selected objects", "Affect all selected objects"),
+                   ('SCENE', "Scene objects", "Affect all objects in the current scene"),
+                   ('ALL', "All", "All objects in this blend file"))
+
 mu_fake_user_set_enums = (('ON', "On", "Enable fake user"),
                           ('OFF', "Off", "Disable fake user"),
                           ('TOGGLE', "Toggle", "Toggle fake user"))
-mu_fake_user_materials_enums = (('ACTIVE', "Active object", "Materials of active object only"),
-                                ('SELECTED', "Selected objects", "Materials of selected objects"),
-                                ('SCENE', "Scene objects", "Materials of objects in current scene"),
-                                ('USED', "Used", "All materials used by objects"),
-                                ('UNUSED', "Unused", "Currently unused materials"),
-                                ('ALL', "All", "All materials in this blend file"))
+mu_fake_user_affect_enums = (('ACTIVE', "Active object", "Materials of active object only"),
+                             ('SELECTED', "Selected objects", "Materials of selected objects"),
+                             ('SCENE', "Scene objects", "Materials of objects in current scene"),
+                             ('USED', "Used", "All materials used by objects"),
+                             ('UNUSED', "Unused", "Currently unused materials"),
+                             ('ALL', "All", "All materials in this blend file"))
 
 mu_link_to_enums = (('DATA', "Data", "Link the materials to the data"),
                     ('OBJECT', "Object", "Link the materials to the object"),
diff --git a/materials_utils/functions.py b/materials_utils/functions.py
index 6c8c72bd..b8afc04f 100644
--- a/materials_utils/functions.py
+++ b/materials_utils/functions.py
@@ -1,4 +1,5 @@
 import bpy
+from math import radians, degrees
 
 # -----------------------------------------------------------------------------
 # utility functions
@@ -54,6 +55,19 @@ def mu_assign_to_data(object, material, index, edit_mode, all = True):
             bpy.ops.object.mode_set(mode = 'OBJECT')
 
 def mu_new_material_name(material):
+    for mat in bpy.data.materials:
+        name = mat.name
+
+        if (name == material):
+            try:
+                base, suffix = name.rsplit('.', 1)
+
+                # trigger the exception
+                num = int(suffix, 10)
+                material = base + "." + '%03d' % (num + 1)
+            except ValueError:
+                material = material + ".001"
+
     return material
 
 
@@ -139,6 +153,15 @@ def mu_assign_material(self, material_name = "Default", override_type = 'APPEND_
                 obj.material_slots[i].material = target
                 i += 1
 
+        elif override_type == 'OVERRIDE_CURRENT':
+            active_slot = obj.active_material_index
+
+            if len(obj.material_slots) == 0:
+                self.report({'INFO'}, 'No material slots found! A material slot was added!')
+                bpy.ops.object.material_slot_add()
+
+            obj.material_slots[active_slot].material = target
+
         # if we should keep the material slots and just append the selected material (if not already assigned)
         elif override_type == 'APPEND_MATERIAL':
             found = False
@@ -184,7 +207,7 @@ def mu_assign_material(self, material_name = "Default", override_type = 'APPEND_
     return {'FINISHED'}
 
 
-def mu_select_by_material_name(self, find_material_name, extend_selection = False):
+def mu_select_by_material_name(self, find_material_name, extend_selection = False, internal = False):
     """Searches through all objects, or the polygons/curves of the current object
     to find and select objects/data with the desired material"""
 
@@ -195,7 +218,7 @@ def mu_select_by_material_name(self, find_material_name, extend_selection = Fals
 
     if find_material is None:
         self.report({'INFO'}, "The material " + find_material_name + " doesn't exists!")
-        return {'CANCELLED'}
+        return {'CANCELLED'} if not internal else -1
 
     # check for edit_mode
     edit_mode = False
@@ -236,9 +259,10 @@ def mu_select_by_material_name(self, find_material_name, extend_selection = Fals
                 obj.select_set(state=False)
 
         if not found_material:
-            self.report({'INFO'}, "No objects found with the material " +
-                                    find_material_name + "!")
-            return {'FINISHED'}
+            if not internal:
+                self.report({'INFO'}, "No objects found with the material " +
+                                        find_material_name + "!")
+            return {'FINISHED'} if not internal else 0
 
     else:
         # it's edit_mode, so select the polygons
@@ -253,7 +277,6 @@ def mu_select_by_material_name(self, find_material_name, extend_selection = Fals
         objects = bpy.context.selected_editable_objects
 


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list