4

Hei all, I have this procedural program that creates different object in Maya through Python. After the creation of these elements I want to get the user the possibility to select some of these object and though a button to delete it...The problem is that I don't understand how to get the name of the object... So far my code is this..

#Deletes Selected Element selected from the user
def DeleteSelection(*args):
    selected = cmds.ls(sl=1,sn=True)
    print(selected)
    #if(cmds.objExists()):
        #cmds.delete(selected)
#

And in the GUI I have this button...

cmds.button(label='Delete Selection', w=150,h=30,command=DeleteSelection)
Stefano Feltre
  • 71
  • 1
  • 4
  • 10

1 Answers1

5

cmds.ls will return a list, you need to check the list and delete what ever you want to delete, and sn is very bad always use long name because there can be duplicates.

selected = cmds.ls(sl=True,long=True) or []
for eachSel in selected:
   cmds.delete(eachSel)
user229044
  • 232,980
  • 40
  • 330
  • 338
Achayan
  • 5,720
  • 2
  • 39
  • 61