如何定期执行Maya MEL过程 [英] How to execute a Maya MEL procedure at regular intervals
问题描述
我希望每x秒执行一次Maya MEL程序.有什么办法吗?
mel设置为
scriptJob -e "idle" "yourScriptHere()";
但是,很难从梅尔那里获得时间(以秒为单位)-system("time/t")将使您得到的时间达到分钟,但没有达到Windows上的秒.在Unix系统中("date + \"%H:%M:%S \")可以使您花费数小时,数分钟和数秒.
这里的scriptJob的主要缺点是,当用户或脚本运行时,不会处理空闲事件-如果GUI或脚本执行了很长时间,则在此期间不会触发任何事件. /p>
您也可以使用Python在线程中执行此操作:
import threading
import time
import maya.utils as utils
def example(interval, ):
global run_timer = True
def your_function_goes_here():
print "hello"
while run_timer:
time.sleep(interval)
utils.executeDeferred(your_function_goes_here)
# always use executeDeferred or evalDeferredInMainThreadWithResult if you're running a thread in Maya!
t = threading.Thread(None, target = example, args = (1,) )
t.start()
线程更强大,更灵活-麻烦很多.它们还受到与scriptJob空闲事件相同的限制;如果玛雅人很忙,他们将不会开火.
I would like one of my Maya MEL procedures to be executed every x seconds. Is there any way to do that ?
The mel setup would be
scriptJob -e "idle" "yourScriptHere()";
However it's hard to get the time in seconds from Mel - system("time /t") will get you time to the minute but not to the second on windows. In Unix system("date +\"%H:%M:%S\"") would get you hours, minutes and seconds.
The main drawback to scriptJob here is that idle events won't be processed when the user or a script is operating - if either the GUI or a script does something long you won't get any events fired during that period.
You can do this in Python with threads as well:
import threading
import time
import maya.utils as utils
def example(interval, ):
global run_timer = True
def your_function_goes_here():
print "hello"
while run_timer:
time.sleep(interval)
utils.executeDeferred(your_function_goes_here)
# always use executeDeferred or evalDeferredInMainThreadWithResult if you're running a thread in Maya!
t = threading.Thread(None, target = example, args = (1,) )
t.start()
Threads are much more powerful and flexible - and a big pain the the butt. They also suffer from the same limitation of as the scriptJob idle event; if Maya's busy they won't fire.
这篇关于如何定期执行Maya MEL过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!