I am building a UI using Python in Maya, a 3D app.
I have a panel in which I want to assign commands to buttons which are created in a loop. The commands have an arg, which is derived from the loop. Using lambda, the button commands all get the same arg, which is the last value in the loop.
It is my understanding that I need to build a callback function to capture the loop values and pass them back to the command, but I don't know how do to this.
If someone could help, I'd greatly appreciate it.
The problematic line is:
cmds.button(l='Sel',w=20, command = lambda *args: selectMe(fullName) )
Thanks very much.
def fillUDPanel(): global sliderContainer sel=cmds.ls(sl=1) if len(sel) == 0: mel.error("You must have an object selected!") for obj in sel: attributes=cmds.listAttr(obj, ud=1) if not attributes : print obj,'doesn\'t have obj user-defined atttrs.' continue cmds.setParent('frameBegin') sliderContainer = cmds.frameLayout('sliderFrame',collapsable=1,l=obj,bs="etchedOut") cmds.rowColumnLayout('sliderPanel', nc = 2, columnWidth=[(2, 40)]) for attr in attributes: fullName=(str(obj) + "." + str(attr)) cmds.attrFieldSliderGrp(cw=(1, 90),at=fullName,cat=(1, 'left', 10)) cmds.button(l='Sel',w=20, command = lambda *args: selectMe(fullName) ) # Uses last attr for all buttons. def selectMe(who): print 'selectMe:',who cmds.select (who)