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

How to get the name of a selected Object Python Maya

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

#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)
#

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

cmds.button(label='Delete Selection', w=150,h=30,command=DeleteSelection)

cmds.ls 会 return 一个列表,你需要检查列表并删除任何你想删除的东西,而且 sn 是非常糟糕的,总是使用长名称,因为可能会有重复。

selected = cmds.ls(sl=True,long=True) or []
for eachSel in selected:
   cmds.delete(eachSel)

ps : 你应该尝试阅读 doc's ,因为你问了这么多基本问题。这么简单的事情就这么问是不公平的。