使用python在maya中设置热键

2024-10-01 15:47:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在研究为python中的一些自定义脚本生成新的热键,并希望使用pm.nameCommandpm.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')

这是工具测试.py上面引用的文件

^{pr2}$

如果您在脚本编辑器中运行以上所有内容,那么它应该可以正常工作。如果你把第一段代码放到一个文件中(热键测试.py)从脚本编辑器中运行,在尝试使用热键时会出现以下错误。在

# Error: line 1: NameError: file <maya console> line 1: name 'toolTest' is not defined # 

有人知道如何使用python从外部脚本为自定义工具设置maya热键吗?在

谢谢!在


Tags: 代码nameimport脚本true编辑器command热键

热门问题