【问题标题】:Setting up a hotkey in maya with python使用python在maya中设置热键
【发布时间】:2014-01-07 17:20:38
【问题描述】:

我正在考虑为 python 中的一些自定义脚本制作新的热键,并希望使用 pm.nameCommand 和 pm.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 热键?

谢谢!

【问题讨论】:

    标签: python maya pymel


    【解决方案1】:

    mel 的 python 函数运行 Python 的 __main__ 模块中的代码,该模块没有 toolTest。

    那就试试吧:

    pm.nameCommand( 'hotkeyTest', ann='Hotkey Test', c='python("import toolTest;toolTest.testing()")')
    

    【讨论】:

      猜你喜欢
      • 2011-03-21
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      相关资源
      最近更新 更多