Custom material library HELP

25 views
Skip to first unread message

lav...@gmail.com

unread,
Jul 24, 2019, 3:40:58 PM7/24/19
to Python Programming for Autodesk Maya
Hello everyone, I'm still new to Python. I'm currently working on a material library where materials (aistandard) are created when a folder with textures with correct naming convention are loaded via a file dialog. Tumbnails Appear in the menu ui when created and you can apply them to objects ofcourse.
I don't understand how I can check if the files have the correct name, load them all in with file dialog and apply them to the correct shading node of 1 material. I would appreciate the help a lot!

Lavux

unread,
Jul 24, 2019, 3:43:32 PM7/24/19
to Python Programming for Autodesk Maya
This is what I have so far:

import maya.cmds as cmds
from os import listdir

class Material_library():
    def __init__(self):
        UI=cmds.window(title="Material Library", widthHeight =(300,150), s=True)
        cmds.rowColumnLayout(numberOfColumns = 1)
        cmds.button(label= "Select texture folder", command= self.select_folder)
        cmds.separator(h=20)
        
        cmds.showWindow()
                
        
    def select_folder(self, *args):          
        myFilter= "Image Files (*.jpg *.jpeg *.tga *.png *.tiff *.bmp *.psd)"
        self.myDirectory = cmds.fileDialog2(fileFilter=myFilter, dialogStyle=1, fm=3)
        myFiles= listdir(self.myDirectory[0])
                    
        for textures in myFiles:
            fileEndings = ('.psd','.PSD','.jpg','JPG','.jpeg','.JPEG','.tga','.TGA','.png','.PNG','.tiff','.TIFF','.bmp','.BMP')
            if textures.endswith(fileEndings):
                myTexture = textures
                
                shader=cmds.shadingNode("AiStandardSurface",asShader=True)

            else:
                cmds.warning(textures + 'This is not a valid image type')
        print myFiles
        
Material_library()         
Reply all
Reply to author
Forward
0 new messages