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!