Maya Python: mel.eval(invertSelection;) 不工作

Maya Python: mel.eval(invertSelection;) not working

正如标题所述,我在 Maya 中有一个简单的 python 脚本无法运行。

import maya.cmds as cmds
import maya.mel as mel

def createCylinder():
    # Check if cylinder "trunkCylinder" exists. Delete it
    if cmds.objExists("trunkCylinder"):
        cmds.delete("trunkCylinder")
    # Create a new cylinder called "trunkCylinder"
    cmds.polyCylinder(axis=(0,1,0), height=1, name="trunkCylinder" )
    # Clear the selection, then select the cap and invert the selection.
    cmds.select(clear=True)
    cmds.select("trunkCylinder.f[21]", replace=True)
    invertedSel = mel.eval("invertSelection;")
    print str(invertedSel)
    # ^^ Prints: None ^^
    # End result is nothing is selected

createCylinder()

我希望 Maya 能够在 trunkCylinder 上打印除 f[21] 之外的所有面的列表,并在视口中反转 selection。相反,它 returns None 和 deselects f[21]。有没有人看到我的代码中有错误,或者我是否错误地使用了 invertSelection?

幸运的是,我可以 select f[0:20] 作为解决方法,或者甚至获取面孔列表并将其与我的面孔列表进行比较,删除两个列表中的任何内容。但是,我已经可以设想让 invertSelection 起作用会节省我很多时间的情况。这里的任何帮助将不胜感激。

下面的 Python 脚本绝对有效。你应该试试))。星号用于选择数组中的所有其他面,以及 toggle 标志,为您反转选择。

import maya.cmds as cmds

def createCylinder():
    if cmds.objExists("trunkCylinder"):
        cmds.delete("trunkCylinder")
    cmds.polyCylinder(axis=(0,1,0), height=1, name="trunkCylinder")
    cmds.select(clear=True)
    cmds.select("trunkCylinder.f[21]")
    cmds.select("trunkCylinder.f[*]", tgl=True)

createCylinder()