[Bf-extensions-cvs] [bb8d8df] master: Materials Utils: Update to version 1.0.1

lijenstina noreply at git.blender.org
Tue Mar 21 19:08:25 CET 2017


Commit: bb8d8dfa56c2086e68785dffe6ea301bbde089eb
Author: lijenstina
Date:   Tue Mar 21 19:06:41 2017 +0100
Branches: master
https://developer.blender.org/rBAbb8d8dfa56c2086e68785dffe6ea301bbde089eb

Materials Utils: Update to version 1.0.1

Bumped version to 1.0.1
New operator VIEW3D_OT_set_new_material_name added
located in the Specials menu
Allows to set the base name of the newly created Material
Also, calls the Preview Active Material upon material creation
(optional)
Small cleanup, Preferences UI fixes

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

M	materials_utils/__init__.py
M	materials_utils/texture_rename.py
M	materials_utils/warning_messages_utils.py

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

diff --git a/materials_utils/__init__.py b/materials_utils/__init__.py
index 019b32b..0934240 100644
--- a/materials_utils/__init__.py
+++ b/materials_utils/__init__.py
@@ -26,7 +26,7 @@
 bl_info = {
     "name": "Materials Utils Specials",
     "author": "Community",
-    "version": (1, 0, 0),
+    "version": (1, 0, 1),
     "blender": (2, 77, 0),
     "location": "Materials Properties Specials/Shift Q",
     "description": "Materials Utils & Convertors",
@@ -69,18 +69,10 @@ from bpy.types import (
             )
 from .warning_messages_utils import (
             warning_messages,
-            c_is_cycles_addon_enabled,
             c_data_has_materials,
             )
 
-# -----------------------------------------------------------------------------
-# Globals #
 
-# set the default name of the new added material
-MAT_DEFAULT_NAME = "New Material"
-
-
-# -----------------------------------------------------------------------------
 # Functions #
 
 def fake_user_set(fake_user='ON', materials='UNUSED', operator=None):
@@ -279,8 +271,7 @@ def mat_to_texface(operator=None):
             if operator and not mats and mixed_obj is False:
                 message_a.append(ob.name)
 
-            # now we have the images
-            # apply them to the uvlayer
+            # now we have the images, apply them to the uvlayer
             me = ob.data
 
             # got uvs?
@@ -355,7 +346,6 @@ def cleanmatslots(operator=None):
 
         # is active object selected ?
         selected = bool(actob.select)
-
         actob.select = True
 
     objs = bpy.context.selected_editable_objects
@@ -435,7 +425,6 @@ def cleanmatslots(operator=None):
 
 def assign_mat_mesh_edit(matname="Default", operator=None):
     actob = bpy.context.active_object
-
     found = False
     for m in bpy.data.materials:
         if m.name == matname:
@@ -472,7 +461,6 @@ def assign_mat_mesh_edit(matname="Default", operator=None):
 
         # assign the material to the object
         bpy.ops.object.material_slot_assign()
-
         actob.data.update()
 
         # restore selection state
@@ -489,7 +477,6 @@ def assign_mat(matname="Default", operator=None):
 
     # is active object selected ?
     selected = bool(actob.select)
-
     actob.select = True
 
     # check if material exists, if it doesn't then create it
@@ -539,7 +526,6 @@ def assign_mat(matname="Default", operator=None):
                         index = i - 1
                 targetlist = [index]
                 assignmatslots(ob, targetlist)
-
             elif ob.type == 'MESH':
                 # check material slots for matname material
                 found = False
@@ -742,7 +728,6 @@ def remove_materials_all(operator=None):
             warning_messages(operator, 'R_OB_FAIL_MAT', collect_mess)
 
 
-# -----------------------------------------------------------------------------
 # Operator Classes #
 
 class VIEW3D_OT_show_mat_preview(Operator):
@@ -835,8 +820,7 @@ class VIEW3D_OT_show_mat_preview(Operator):
             layout.label(text="**Only Undo is available**", icon="INFO")
 
     def check(self, context):
-        if self.is_not_undo is True:
-            return True
+        return self.is_not_undo
 
     def execute(self, context):
         self.is_not_undo = False
@@ -900,28 +884,65 @@ class VIEW3D_OT_texface_to_material(Operator):
             return {'CANCELLED'}
 
 
+class VIEW3D_OT_set_new_material_name(Operator):
+    bl_idname = "view3d.set_new_material_name"
+    bl_label = "New Material Settings"
+    bl_description = ("Set the Base name of the new Material\n"
+                      "and tweaking after the new Material creation")
+    bl_options = {'REGISTER'}
+
+    def invoke(self, context, event):
+        return context.window_manager.invoke_props_dialog(self)
+
+    def draw(self, context):
+        layout = self.layout
+        scene = context.scene.mat_specials
+
+        box = layout.box()
+        box.label("Base name:")
+        box.prop(scene, "set_material_name", text="", icon="SYNTAX_ON")
+        layout.separator()
+        layout.prop(scene, "use_tweak")
+
+    def execute(self, context):
+        return {'FINISHED'}
+
+
 class VIEW3D_OT_assign_material(Operator):
     bl_idname = "view3d.assign_material"
     bl_label = "Assign Material"
     bl_description = "Assign a material to the selection"
     bl_options = {'REGISTER', 'UNDO'}
 
-    is_edit = False
-
+    is_existing = BoolProperty(
+        name="Is it a new Material",
+        options={'HIDDEN'},
+        default=True,
+        )
     matname = StringProperty(
-            name="Material Name",
-            description="Name of Material to Assign",
-            default=MAT_DEFAULT_NAME,
-            maxlen=128,
-            )
+        name="Material Name",
+        description="Name of the Material to Assign",
+        options={'HIDDEN'},
+        default="Material_New",
+        maxlen=128,
+        )
 
     @classmethod
     def poll(cls, context):
         return context.active_object is not None
 
+    def invoke(self, context, event):
+        return self.execute(context)
+
     def execute(self, context):
         actob = context.active_object
         mn = self.matname
+        scene = context.scene.mat_specials
+        tweak = scene.use_tweak
+
+        if not self.is_existing:
+            new_name = check_mat_name_unique(scene.set_material_name)
+            mn = new_name
 
         if (actob.type in {'MESH'} and actob.mode in {'EDIT'}):
             assign_mat_mesh_edit(mn, self)
@@ -932,9 +953,13 @@ class VIEW3D_OT_assign_material(Operator):
             cleanmatslots()
 
         mat_to_texface()
+        self.is_not_undo = False
 
-        # reset the passing string
-        self.matname = ""
+        if tweak:
+            try:
+                bpy.ops.view3d.show_mat_preview('INVOKE_DEFAULT')
+            except:
+                self.report({'INFO'}, "Preview Active Material could not be opened")
 
         return {'FINISHED'}
 
@@ -988,8 +1013,8 @@ class VIEW3D_OT_material_remove_slot(Operator):
     bl_options = {'REGISTER', 'UNDO'}
 
     @classmethod
-    # materials can't be removed in Edit mode
     def poll(cls, context):
+        # materials can't be removed in Edit mode
         return (c_data_has_materials() and
                 context.active_object is not None and
                 not context.object.mode == 'EDIT')
@@ -1011,8 +1036,8 @@ class VIEW3D_OT_material_remove_object(Operator):
     bl_options = {'REGISTER', 'UNDO'}
 
     @classmethod
-    # materials can't be removed in Edit mode
     def poll(cls, context):
+        # materials can't be removed in Edit mode
         return (c_data_has_materials() and
                 context.active_object is not None and
                 not context.object.mode == 'EDIT')
@@ -1034,8 +1059,8 @@ class VIEW3D_OT_material_remove_all(Operator):
     bl_options = {'REGISTER', 'UNDO'}
 
     @classmethod
-    # materials can't be removed in Edit mode
     def poll(cls, context):
+        # materials can't be removed in Edit mode
         return (c_data_has_materials() and
                 context.active_object is not None and
                 not context.object.mode == 'EDIT')
@@ -1057,6 +1082,7 @@ class VIEW3D_OT_select_material_by_name(Operator):
     bl_label = "Select Material By Name"
     bl_description = "Select geometry with this material assigned to it"
     bl_options = {'REGISTER', 'UNDO'}
+
     matname = StringProperty(
             name='Material Name',
             description='Name of Material to Select',
@@ -1135,10 +1161,9 @@ class VIEW3D_OT_fake_user_set(Operator):
             items=(('ON', "On", "Enable fake user"), ('OFF', "Off", "Disable fake user")),
             default='ON',
             )
-
     materials = EnumProperty(
             name="Materials",
-            description="Which materials of objects to affect",
+            description="Chose what objects and materials to affect",
             items=(('ACTIVE', "Active object", "Materials of active object only"),
                    ('SELECTED', "Selected objects", "Materials of selected objects"),
                    ('SCENE', "Scene objects", "Materials of objects in current scene"),
@@ -1289,14 +1314,12 @@ class MATERIAL_OT_link_to_base_names(Operator):
                 name="Material to keep",
                 default="",
                 )
-
     is_auto = BoolProperty(
                 name="Auto Rename/Replace",
                 description=("Automatically Replace names "
                              "by stripping numerical suffix"),
                 default=False,
                )
-
     mat_error = []          # collect mat for warning messages
     is_not_undo = False     # prevent drawing props on undo
     check_no_name = True    # check if no name is passed
@@ -1374,14 +1397,14 @@ class MATERIAL_OT_link_to_base_names(Operator):
             return
 
         base, suffix = self.split_name(slot.material)
-
         if suffix is None:
             return
 
         try:
             base_mat = bpy.data.materials[base]
         except KeyError:
-            print("Link to base names: Base material %r not found" % base)
+            print("\n[Materials Utils Specials]\nLink to base names\nError:"
+                  "Base material %r not found\n" % base)
             return
 
         slot.material = base_mat
@@ -1460,7 +1483,6 @@ class MATERIAL_OT_check_converter_path(Operator):
         return {'FINISHED'}
 
 
-# -----------------------------------------------------------------------------
 # Menu classes #
 
 class VIEW3D_MT_assign_material(Menu):
@@ -1473,19 +1495,22 @@ class VIEW3D_MT_assign_material(Menu):
         if c_data_has_materials():
             # no materials
             for material_name in bpy.data.materials.keys():
-                layout.operator("view3d.assign_material",
+                mats = layout.operator("view3d.assign_material",
                                 text=material_name,
-                                icon='MATERIAL_DATA').matname = material_name
+                                icon='MATERIAL_DATA')
+                mats.matname = material_name
+                mats.is_existing = True
             use_separator

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list