我正在考虑为 python 中的一些自定义脚本制作新的热键,并想使用pm.nameCommand
andpm.hotkey
命令。问题是,当我从脚本编辑器运行以下代码时,它运行良好并且一切都很好,但是当我从脚本运行它时,我在尝试使用热键时遇到错误。
import pymel.core as pm
import toolTest
#clear existing hotkey
pm.hotkey(keyShortcut='a', ctrlModifier=True, name='')
#create named command for custom tool
#For some reason you need to run the python tool command through a python command in mel
pm.nameCommand( 'hotkeyTest', ann='Hotkey Test', c='python(\"toolTest.testing()\");')
#assign it a hotkey
pm.hotkey( keyShortcut='a', ctrlModifier=True, name='hotkeyTest')
这是上面引用的toolTest.py文件
def testing():
print "Testing Hotkeys"
如果您在脚本编辑器中运行上述所有内容,那么它应该可以正常工作。然后,如果您将第一部分代码放入文件 (hotkeyTest.py) 并从脚本编辑器运行,您在尝试使用热键时会收到以下错误。
# Error: line 1: NameError: file <maya console> line 1: name 'toolTest' is not defined #
有谁知道如何使用 python 从外部脚本为自定义工具设置 Maya 热键?
谢谢!