Python 玛雅';names命令无法调用函数

Python 玛雅';names命令无法调用函数,python,maya,Python,Maya,我在Maya中与热键一起使用的nameCommand中调用函数时遇到问题。我不知道这是Maya还是Python的问题 以下MEL按预期工作 proc myTest() { print("test"); } nameCommand -ann "test" -command "myTest()" testCommand; hotkey -k "l" -name "testCommand"; 然而,翻译成Python后,我得到了一个错误 import maya.cmds as cmds

我在Maya中与热键一起使用的nameCommand中调用函数时遇到问题。我不知道这是Maya还是Python的问题

以下MEL按预期工作

proc myTest() {
    print("test");
}

nameCommand -ann "test" -command "myTest()" testCommand;
hotkey -k "l" -name "testCommand";
然而,翻译成Python后,我得到了一个错误

import maya.cmds as cmds

def myPythonTest():
    print("myPythonTest")

cmds.nameCommand("pythonTestCommand", ann="pythonTest", command="myPythonTest()", sourceType="python")
cmds.hotkey(k="l", name="pythonTestCommand")

// Error: line 1: Cannot find procedure "myPythonTest".
在Python中调用函数是错误的方法,还是发生了其他事情?我注意到括号被去掉了,从脚本编辑器用
myPythonTest()
调用函数的效果与预期一样

cmds.nameCommand("pythonTestCommand", ann="pythonTest", command='python("myPythonTest()")', sourceType="python")
cmds.hotkey(k="l", name="pythonTestCommand")

我认为前面的答案在评估中是正确的 该源类型似乎已损坏

如果希望能够将python代码传递给
nameCommand
,则需要 首先创建一个
runTimeCommand

def testy():
打印('你好')
#无法编辑运行时命令,因此我们需要检查它是否正确
#存在,如果存在,则将其删除。
my_command_name='my_runtime_command'
如果cmds.runTimeCommand(我的命令名,q=True,exists=True):
runTimeCommand(我的命令名,e=True,delete=True)
cmds.runTimeCommand(
我的命令名,
安:‘我的命令’,
category='User',
命令='testy()',
commandLanguage='python'
)
cmds.nameCommand('my\u name\u command',ann='my command',command=my\u command\u name)
cmds.hotkey(k='1',name='my\u name\u command')
正如您所看到的,您不需要提供sourceType,
nameCommand
runtimecommand的字符串表示形式,将只执行
给定
runTimeCommand
。因此,指定执行语言的真正位置是
runTimeCommand

commandLanguage
标志,谢谢,这正是所需要的。出于好奇和理解:为什么它会起作用?python(“”)是做什么的?我认为sourceType实际上不起作用,所以在这里我看到了使用python mel命令调用python函数。我试着在谷歌上搜索python函数,并在文档中查找它,不过是在python命令中,而不是在mel中。但是很好,有点道理,谢谢你回复我。