Maya Python:我列出了一个团体的亲戚,但是当我去 select 亲戚时它说 none

Maya Python : Im listing relatives of a group but when i go to select the relatives it says none

您好,我想在 Maya 中列出该组的所有亲属。它 returns 列表很好,但是当我转到 select 列表中的所有内容时,它打印出 none 是 selected?

mySel = cmds.ls(selection=True)
print(mySel)

rel = cmds.listRelatives(ad=True , pa=True)
print(mySel)

cmds.rename(mySel + '_grp')

欢迎来到 SO!

现在,当您使用 cmds.ls(selection=True) 捕获选择时,它会 return 给您一个字符串列表。

重命名方法需要 2 个 strings 作为参数、要重命名的现有对象以及要将其重命名为什么。

所以您现在正在做的是传递 mySel 整个字符串列表,而它只接受一个字符串。如果要一次重命名多个对象,则需要使用 for 循环对它们进行一个一个地操作:

import maya.cmds as cmds

mySel = cmds.ls(selection=True) # Get a list of the current selection.

for i, obj in enumerate(mySel): # Loop over selection, one by one.
    newName = "{}_{}_grp".format(obj, i) # Build the new name.
    cmds.rename(obj, newName) # Finally rename the object.

还有 cmds.listRelatives 如果对象没有 shapes/children 或者您根本没有选择任何东西,它可能会 return None。所以你可能需要一个 if 条件来确保它 return 是什么。

希望这样更清楚。