On Sun, Sep 6, 2015 at 9:22 AM Maria Jesus Penella <[email protected]> wrote:
> Thanks ! I think my problem it that I don't know exactly how layout and >> parents works in python... i'm just improvising a bit... Now I have created >> a layout just for the buttons and it deletes them ok, but if I do any >> change ( add or delete light ) I have a blank space where the buttons >> should be.. I attach this time the whole code for this to work =) >> > Yea, it was not possible to run this code, as pasted. I had to fix and format things. Also the parenting was not correct and I would get all the light buttons created within Mayas attribute editor (last parent). Please use pastebin.com or some other code pasting site for long code in the future. It will definitely help. I just took the liberty of refactoring your code: http://pastebin.com/2KvjJ7bN Things to note: Can't use spaces in window name. It will always correct it and you will never match. Moved layouts around to make deleting the buttons easier and cleaner, and using a scroll layout now. Various other adjustments there as well. Let me know if you need specific details. Maybe this works a bit better for you without having to change too much of your original code? Justin > > import maya.cmds as cmds > import maya.mel as mel > import pymel.core as pm > > class createWindowClass(object): > def __init__(self, *args): > pass > def show(self): > self.createWindow() > > def turnOn(self, totalLgt, name, *args): > # turns on/off the light > def turnSolo(self,totalLgt, name, *args): > # just that light affect > > def updateList(self, name, lgt, totalLgt, *args): > > #create new buttons > self.text = pm.text(name, label="Name: %s" %name) > visibilityLgt = pm.getAttr(lgt+'.visibility') > if visibilityLgt == True: > > self.button = pm.button(name, label="ON" ,command = lambda > *args: self.turnOn(totalLgt, name)) > else: > self.button = pm.button(name, label="OFF" ,command = lambda > *args: self.turnOn(totalLgt, name)) > self.button = pm.button('btnNameS'+str(totalLgt), label="SOLO", > command = lambda *args: self.turnSolo(totalLgt, name)) > pm.attrColorSliderGrp(at='%s.color' % name ) > pm.attrFieldSliderGrp( min=0.0, max=10.0, at='%s.intensity' % name > ) > > def update(self, totalLgt,lis, butLayout, *args): > if pm.layout(butLayout, exists = True): > pm.deleteUI(butLayout) > self.lightLst() > > def lightLst(self, *args): > butLayout = pm.rowColumnLayout(numberOfColumns=1, > columnWidth=[(10,120)], columnOffset=[10,"right",5]) > totalLgt = 0 > lis = pm.ls(type='light') > pm.button('buttonMain',label="UPDATE", e= True ,command = lambda * > args: self.update(totalLgt,lis, butLayout )) > #list all lights in scene > for lgt in lis: > totalLgt += 1 > nameLgt = lgt.longName() > name = nameLgt.split("|")[1] > self.updateList(name, lgt, totalLgt) > pm.setParent('..') > > #CREATE WINDOW > > def createWindow(self): > > windowID = 'Light Control' > if pm.window(windowID, exists = True): > pm.deleteUI(windowID) > > self.window = pm.window(windowID, title = "Modify Lights", width > = 100, sizeable = True) > pm.rowColumnLayout(numberOfColumns=1, columnWidth=[(10,120)], > columnOffset=[10,"right",5]) > pm.text(label=" ******** Light list ******** \n") > > pm.button('buttonMain', label="CREATE" ,enable = True , command = > lambda *args: self.lightLst()) > > pm.text(label= " \n ***************************** \n ") > pm.setParent('..') > pm.showWindow(self.window) > > cls = createWindowClass() > cls.show() > >> >> > > > Thank you!! =) I'm sorry my code is kinda messy thou.. > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/dd3ab467-f72f-40ac-8ef1-2d3239a4bb08%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/dd3ab467-f72f-40ac-8ef1-2d3239a4bb08%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3uT0e1%3DbJe2AEtevcBv2VKSyZOTAwEXQxpJMU52aLtjQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
