Search code examples
loopsbuttoncommandmayaclick

Query Button Name when clicked


In Maya:

I am building a dynamic UI which creates for each character a button with the characters name. To keep stuff simple I want to print the name of the button when it is clicked. I can't get it to work, because the buttons are create with just one btn=cmds.button('%sBtn'%character,c="print btn") line. So when I click the button only the last created button in the for loop is printed.. Any ideas?


Solution

  • cmds.window( width=150 )
    cmds.columnLayout( adjustableColumn=True )
    for i in range(5):
        btnName = 'button'+str(i)
        btnCmd = ('print \'%s\'')%(btnName)
        cmds.button( btnName, label='Button 1', command=btnCmd )
    cmds.showWindow()