Multiple optionMenu lists working with one directory problem

16 views
Skip to first unread message

Anastasia Korol

unread,
Jun 22, 2021, 6:42:59 PM6/22/21
to Python Programming for Autodesk Maya
Hi guys! I am doing simple UI for choosing textures for two nodes in the shader and I can't make the optionMenu command to work one by one with the same source for the both optionMenu1 and optionMenu2. I have one directory to choose and need two similar lists where user can choose the texture file and apply it on two different nodes. So far I am interested only in understanding how to make both of the optionMenus work with one folder button:




import maya.cmds as cmds
from os import listdir

class AK_TextureLink(object):
    def __init__(self):
        self.window = 'ShaderWindow'
        self.title = 'Layered Shader Window'
        self.size = (600, 250)
        self.createWindow()
        
    def createWindow(self):
        if cmds.window(self.window, exists = True):
            cmds.deleteUI(self.window, window = True)
            
        self.window = cmds.window(self.window, title = self.title, widthHeight = self.size)
        
        
        self.mainForm = cmds.formLayout(numberOfDivisions = 100);
        
        self.titleDisplay = cmds.text(label = self.title, align="center", font = 'boldLabelFont')
        cmds.formLayout(self.mainForm, edit = True, attachForm=( [self.titleDisplay, 'top', 5],
                                                                 [self.titleDisplay, 'left', 5],
                                                                 [self.titleDisplay, 'right', 5] ))
                                                                 
                                                                 
        
        self.titleSeparator = cmds.separator();
        cmds.formLayout(self.mainForm, edit=True, attachControl = [self.titleSeparator, 'top', 10, self.titleDisplay],
                                                  attachForm = ([self.titleSeparator, 'left', 5],
                                                                [self.titleSeparator, 'right', 5] ))
        #creating the button for folder choice                                                        
        self.btnFolderSet1 = cmds.button(label='Set Texture Folder', height=30, width=150, command=self.SetFolderBtnCmd1)
        cmds.formLayout(self.mainForm, edit=True, attachControl = [self.btnFolderSet1, 'top', 30, self.titleDisplay],
                                                  attachForm = [self.btnFolderSet1, 'left', 5])
                                                  
                                                          
        #the first list which i want to work with folder choice button
        self.firstTextureList = cmds.optionMenu('optionMenu1',label="First File List")
        cmds.formLayout(self.mainForm, edit=True, attachControl = [self.firstTextureList, 'top', 30, self.btnFolderSet1],
                                                  attachForm = [self.firstTextureList, 'left', 5])
                                                  
        
        #the second list which is working with folder button                                          
        self.secondTextureList = cmds.optionMenu('optionMenu2',label="Second File List")
        cmds.formLayout(self.mainForm, edit=True, attachControl = ([self.secondTextureList, 'top', 30, self.btnFolderSet1],
                                                                   [self.secondTextureList, 'left', 20, self.firstTextureList]))
                                                                   
                                                                         
        
        self.btnApplyShader = cmds.button(label='Apply Shader', height=30, width=150, command=self.applyShaderBtnCmd)
        cmds.formLayout(self.mainForm, edit=True, attachControl = [self.btnApplyShader, 'top', 20, self.firstTextureList],
                                                  attachForm = [self.btnApplyShader, 'left', 5])
                                                  
        cmds.showWindow()                                          
        
    def SetFolderBtnCmd1(self, *args):
        print 'button pressed' 
        basicFilter = "Image Files (*.jpg *.jpeg *.tga *.png *.tiff *.bmp *.psd)"
        self.myDir = cmds.fileDialog2 (fileFilter=basicFilter, dialogStyle=2, fm=3)
        myFiles = listdir(self.myDir[0])
        
        for items in myFiles:
            fileEndings = ('.psd','.PSD','.jpg','JPG','.jpeg','.JPEG','.tga','.TGA','.png','.PNG','.tiff','.TIFF','.bmp','.BMP')
            if items.endswith(fileEndings):
                cmds.menuItem(items)
            else:
                cmds.warning(items + 'This is not a valid image type, you fool.')
                
        print myFiles

        
    def applyShaderBtnCmd(self, *args):
        print 'shader button pressed'

       
myTextureRelink = AK_TextureLink()



Thank you!
         
        
Screenshot 2021-06-22 154131.png

Justin Israel

unread,
Jun 22, 2021, 7:05:47 PM6/22/21
to python_in...@googlegroups.com
On Wed, Jun 23, 2021 at 10:43 AM Anastasia Korol <anastas...@gmail.com> wrote:
Hi guys! I am doing simple UI for choosing textures for two nodes in the shader and I can't make the optionMenu command to work one by one with the same source for the both optionMenu1 and optionMenu2. I have one directory to choose and need two similar lists where user can choose the texture file and apply it on two different nodes. So far I am interested only in understanding how to make both of the optionMenus work with one folder button:

The button should only be able to attach to a single layout, because the layout takes ownership of its position. You should try creating a second instance of the button for the second layout.
 
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/56aac8d9-9eaa-47a9-a8e4-f81c6bb70e57n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages