Maya Python 中的 cmds.scriptCtx 究竟是做什么的?

What exactly the cmds.scriptCtx in Maya Python does?

我想知道 cmds.scriptCtx 命令究竟做了什么,因为我试图将它直接从 Autodesk 帮助页面复制并粘贴到我的脚本编辑器中,但没有任何反应。这是来自 Autodesk 帮助的脚本:

import maya.cmds as cmds

cmds.scriptCtx( title='Attach Curve', totalSelectionSets=1, fcs="select -r $Selection1; performAttachCrv 0 \"\"", cumulativeLists=True, expandSelectionList=True, setNoSelectionPrompt='Select two curves close to the attachment points', setSelectionPrompt='Select a second curve close to the attachment point', setDoneSelectionPrompt='Never used because setAutoComplete is set', setAutoToggleSelection=True, setSelectionCount=2, setAutoComplete=True, curveParameterPoint=True )

我尝试了 select 一条曲线和两条曲线,或者根本没有 select 任何东西,但什么也没发生。我错过了什么吗?

我为此脚本使用 Maya 2018。

谢谢大家。

我也一直在想这个命令是什么,但是我从来没有见过别人用过它所以总是忽略它。

不要因为没有得到它而难过,文档在解释示例如何工作方面做得非常糟糕。我不得不四处寻找,发现它完全忽略了您需要使用 cmds.setToolTo().

创建 2 条曲线,运行 这个,然后一次选择一条曲线:

import maya.cmds as cmds

picker = cmds.scriptCtx(
    title='Attach Curve', totalSelectionSets=1, fcs="select -r $Selection1; performAttachCrv 0 \"\"", 
    cumulativeLists=True, expandSelectionList=True, setNoSelectionPrompt='Select two curves close to the attachment points', 
    setSelectionPrompt='Select a second curve close to the attachment point', setDoneSelectionPrompt='Never used because setAutoComplete is set', 
    setAutoToggleSelection=True, setSelectionCount=2, setAutoComplete=True, curveParameterPoint=True
)


cmds.setToolTo(picker)

基本上,它是一个对象选择器。当你 运行 它时,光标会改变,它会为用户显示说明。在此示例中,它表示选择 2 条曲线。当您选择一条曲线时,说明会更新为选择另一条曲线。选择另一个曲线时,脚本运行 s可以连接这两个曲线。用户也可以随时点击 esc 取消它。所有掩码参数都在那里,以便您可以限制用户可以选择的对象类型。

来自 3dsMax 这实际上非常棒,但实现感觉很差。用户根本看不出这个选择器正在发生。这些说明无论如何都没有着色,而且很容易在 Maya 界面的底角被忽略。你也不能从大纲中选择一个对象,这是非常糟糕的设计。据我了解它只支持MEL。

知道它有点酷,但我仍然不认为我会使用它。