2014-01-07 3 views
0

파이썬에서 사용자 정의 스크립트를위한 새로운 단축키를 만들고 싶었고 pm.nameCommandpm.hotkey 명령을 사용하고 싶었습니다. 문제는 스크립트 편집기에서 다음 코드를 실행하면 정상적으로 실행되고 모든 것이 멋지지만 핫키를 사용하려고 할 때 스크립트에서 실행하면 오류가 발생한다는 것입니다. 여기 Maya에서 단축키를 파이썬으로 설정하기

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') 

당신이 그때는 잘 작동합니다 스크립트 편집기에서 위의 모든 것을 실행하면

def testing(): 
    print "Testing Hotkeys" 

위에 언급 된 toolTest.py 파일입니다. 그런 다음 코드의 첫 번째 섹션을 파일 (hotkeyTest.py)에 넣고 스크립트 편집기에서 실행하면 바로 가기 키를 사용하는 동안 다음 오류가 발생합니다.

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

파이썬을 사용하여 외부 스크립트의 맞춤 도구에 대한 단축키를 설정하는 방법을 아는 사람이 있습니까?

감사합니다.

답변

1

mel 함수는 toolTest이없는 Python의 __main__ 모듈에서 코드를 실행합니다.

그래서 시도 :

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