如何在Python Maya中获取所选对象的名称

4

大家好,我有一个通过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)

在GUI中,我有一个按钮...
cmds.button(label='Delete Selection', w=150,h=30,command=DeleteSelection)
1个回答

5

cmds.ls会返回一个列表,您需要检查该列表并删除任何您想要删除的内容,因为可能存在重复项,所以请始终使用长名称而不是sn。

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

谢谢回答!“doc”是什么? - Stefano Feltre
哦,我知道Maya页面...只是因为我尝试过,但我没能弄明白...不过好的,下次我会再试试 :) - Stefano Feltre
另外还有这个链接:http://stackoverflow.com/documentation/maya/7564/finding-scene-objects#t=201703251839167615943 - theodox

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接