i would like to create an add-on in python that can check the name of textures and if a texture is not well named, the add-on propose to rename it.
For that i would like to make a UI instead of input("rename")
I try to make a dialog box, but i didn't succed.
def createBadTextureList():
badTextureList = []
goodTexture = re.compile(r"^[DNR]_.*")
modele = re.compile(r"^modele_.*")
for image in bpy.data.images:
if not(image.name == "Render Result" or image.name == "Viewer Node" or modele.match(image.name)):
if not(goodTexture.match(image.name)):
badTextureList.append(image)
return badTextureList
class TextureName(bpy.types.Operator):
bl_idname="object.texture_name"
bl_label="Vérifier le nom des textures"
bl_description="Verifier que les textures respecte la nommenclature suivante : 'D_' ou 'N_' ou 'R_'"
@classmethod
def poll(cls, context):
return True
def execute(self, context):
badTextureList = createBadTextureList()
for texture in badTextureList:
print("la texture " + texture.name + " est mal nommée")
newName = input("renommer")
texture.name = newName
return {"FINISHED"}
class MyPanel(bpy.types.Panel):
bl_label = "Export"
bl_idname = "VIEW_3D_PT_Export"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "SNCF"
def draw(self, context):
self.layout.label(text = "Nomenclature :")
self.layout.label(text = "- Modèle : 'modele_...'")
self.layout.label(text = "- Texture : ")
self.layout.label(text = " Diffuse : 'D_...'" )
self.layout.label(text = " Normal = 'N_...'" )
self.layout.label(text = " Rougthness = 'R_...'" )
self.layout.column().operator(TextureName.bl_idname)
classes = [MyPanel, TextureName]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
if name == "main":
register()
Does anybody have an idea ? Thanks