diff options
Diffstat (limited to 'materials_utils/texture_rename.py')
-rw-r--r-- | materials_utils/texture_rename.py | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/materials_utils/texture_rename.py b/materials_utils/texture_rename.py index c803295e..585a3a7d 100644 --- a/materials_utils/texture_rename.py +++ b/materials_utils/texture_rename.py @@ -3,31 +3,41 @@ import bpy from bpy.types import ( - Operator, - Panel, - ) -from bpy.props import StringProperty + Operator, + Panel, +) +from bpy.props import ( + BoolProperty, + StringProperty, +) from .warning_messages_utils import ( - warning_messages, - c_data_has_images, - ) + warning_messages, + c_data_has_images, +) class TEXTURE_OT_patern_rename(Operator): bl_idname = "texture.patern_rename" bl_label = "Texture Renamer" bl_description = ("Replace the Texture names pattern with the attached Image ones\n" - "Works on all Textures (Including Brushes) \n \n" - "The First field - the name pattern to replace \n" - "The Second - searches for existing names \n") + "Works on all Textures (Including Brushes)\n" + "The First field - the name pattern to replace\n" + "The Second - search for existing names") bl_options = {'REGISTER', 'UNDO'} def_name = "Texture" # default name is_not_undo = False # prevent drawing props on undo + named = StringProperty( - name="Search for name", - default=def_name - ) + name="Search for name", + description="Enter the name pattern or choose the one from the dropdown list below", + default=def_name + ) + replace_all = BoolProperty( + name="Replace all", + description="Replace all the Textures in the data with the names of the images attached", + default=False + ) @classmethod def poll(cls, context): @@ -35,28 +45,35 @@ class TEXTURE_OT_patern_rename(Operator): def draw(self, context): layout = self.layout - if self.is_not_undo is True: - box = layout.box() - box.prop(self, "named", text="Name pattern", icon="SYNTAX_ON") - layout.separator() + if not self.is_not_undo: + layout.label(text="*Only Undo is available*", icon="INFO") + return + + layout.prop(self, "replace_all") - box = layout.box() - box.prop_search(self, "named", bpy.data, "textures") - else: - layout.label(text="**Only Undo is available**", icon="INFO") + box = layout.box() + box.enabled = not self.replace_all + box.prop(self, "named", text="Name pattern", icon="SYNTAX_ON") + + box = layout.box() + box.enabled = not self.replace_all + box.prop_search(self, "named", bpy.data, "textures") def invoke(self, context, event): self.is_not_undo = True return context.window_manager.invoke_props_dialog(self) + def check(self, context): + return self.is_not_undo + def execute(self, context): errors = [] # collect texture names without images attached - tex_count = 0 # check if there is textures at all + tex_count = len(bpy.data.textures) for texture in bpy.data.textures: try: - if texture and self.named in texture.name and texture.type in {"IMAGE"}: - tex_count += 1 + is_allowed = self.named in texture.name if not self.replace_all else True + if texture and is_allowed and texture.type in {"IMAGE"}: textname = "" img = (bpy.data.textures[texture.name].image if bpy.data.textures[texture.name] else None) if not img: @@ -67,7 +84,7 @@ class TEXTURE_OT_patern_rename(Operator): else: break texture.name = textname - if texture.type != "IMAGE": # rename specific textures as clouds, environnement map,... + if texture.type != "IMAGE": # rename specific textures as clouds, environment map... texture.name = texture.type.lower() except: continue @@ -86,7 +103,6 @@ class TEXTURE_OT_patern_rename(Operator): class TEXTURE_PT_rename_panel(Panel): - # Creates a Panel in the scene context of the properties editor bl_label = "Texture Rename" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' @@ -98,13 +114,13 @@ class TEXTURE_PT_rename_panel(Panel): def register(): - bpy.utils.register_module(__name__) - pass + bpy.utils.register_class(TEXTURE_OT_patern_rename) + bpy.utils.register_class(TEXTURE_PT_rename_panel) def unregister(): - bpy.utils.unregister_module(__name__) - pass + bpy.utils.unregister_class(TEXTURE_PT_rename_panel) + bpy.utils.unregister_class(TEXTURE_OT_patern_rename) if __name__ == "__main__": |