如何获取选定对象Python Maya的名称

Ste*_*tre 4 python ls selection maya

大家好,我有此过程程序可通过Python在Maya中创建不同的对象。创建完这些元素之后,我想让用户可以选择其中一些对象,并且可以通过按钮将其删除...问题是我不了解如何获取对象的名称...到目前为止,我的代码是这样。

#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)
Run Code Online (Sandbox Code Playgroud)

在GUI中,我有这个按钮...

cmds.button(label='Delete Selection', w=150,h=30,command=DeleteSelection)
Run Code Online (Sandbox Code Playgroud)

Ach*_*yan 5

cmds.ls将返回一个列表,您需要检查该列表并删除要删除的内容,并且sn很糟糕,请始终使用长名称,因为可能存在重复项。

selected = cmds.ls(sl=True,long=True) or []
for eachSel in selected:
   cmds.delete(eachSel)
Run Code Online (Sandbox Code Playgroud)

ps:由于您问了太多基本问题,因此您应该尝试阅读doc。问这样的简单事情是不公平的。