how can i delete buttons from UI (python)???


#1

how can i delete buttons from UI ???

i can add buttons from selection but i don’t know how to remove from UI :hmm:

Can someone help me?
Here is my code:

import maya.cmds as cmds
from functools import partial

selList = cmds.ls(sl=True)

window = cmds.window( title="Picker", widthHeight=(200, 55) )
lay = cmds.columnLayout( adjustableColumn=True )

cmds.button(label='Add Controls', command='addBtn()')

def doSelect(objSel, *args):
	cmds.select(objSel, replace=True)
	print objSel	
	
for obj in selList:
	cmds.rowLayout(numberOfColumns=3, columnWidth3=(80, 75, 150), adjustableColumn=True, parent=lay)
	cmds.button(label=obj, command=partial(doSelect, obj))
	cmds.button(label="Remove")
	
def addBtn():
	addSel = cmds.ls(sl=True)
	for obj in addSel:
		cmds.rowLayout(numberOfColumns=3, columnWidth3=(80, 75, 150), adjustableColumn=True, parent=lay)
		cmds.button(label=obj, command=partial(doSelect, obj))
		cmds.button(label="Remove")	
	
cmds.showWindow( window )

#2

Please use the “#” sign to enclose your code in code tags. Something like this:

def addBtn():
addSel = cmds.ls(sl=True)
for obj in addSel:
cmds.rowLayout(numberOfColumns=3, columnWidth3=(80, 75, 150), adjustableColumn=True, parent=lay)
cmds.button(label=obj, command=partial(doSelect, obj))
cmds.button(label="Remove") 

is completely unreadable. With code tags you get correct formatting:

def addBtn():
    addSel = cmds.ls(sl=True)
    for obj in addSel:
        cmds.rowLayout(numberOfColumns=3, columnWidth3=(80, 75, 150), adjustableColumn=True, parent=lay)
        cmds.button(label=obj, command=partial(doSelect, obj))    
        cmds.button(label="Remove") 

Concerning your problem: You can either remove the button by it’s name if you do:

buttonName = cmds.button(label=obj, command=partial(doSelect, obj))    

And later do a deleteUI(buttonName) or you simply try to create a list of buttons and rebuild the entire rowLayout from this list. If you want to remove one element, you can delete it from the list, delete the rowLayout UI and rebuild it.