0

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

Leandre
  • 21
  • 2
  • is this helpful? https://blender.stackexchange.com/questions/109711/how-to-popup-simple-message-box-from-python-console – Harry McKenzie Jul 07 '22 at 08:17
  • Does this answer your question: https://blender.stackexchange.com/questions/57306/how-to-create-a-custom-ui – Robert Gützkow Jul 07 '22 at 08:20
  • Thanks, but unfortunately no. The problem with a simple UI is that i can't ask to an user to enter text in a loop. I have to create a bpy.props for every texture i want to rename. But the way props are created doesn't work with a loop. – Leandre Jul 07 '22 at 08:27
  • Perhaps you are looking for a UIList then? – Robert Gützkow Jul 07 '22 at 08:34

0 Answers0