gpt4 book ai didi

timer - 如何定期执行 Maya MEL 过程

转载 作者:行者123 更新时间:2023-12-02 21:36:53 24 4
gpt4 key购买 nike

我希望每 x 秒执行一次 Maya MEL 程序。有什么办法可以做到这一点吗?

最佳答案

梅尔设置是

scriptJob -e "idle" "yourScriptHere()";

然而,很难从 Mel 处获取以秒为单位的时间 - system("time/t") 会让你得到分钟的时间,但在 Windows 上却无法得到秒的时间。在 Unix 系统中("date +\"%H:%M:%S\"") 会得到小时、分钟和秒。

此处 scriptJob 的主要缺点是,当用户或脚本运行时,不会处理空闲事件 - 如果 GUI 或脚本执行较长时间的操作,则在此期间不会触发任何事件。

您也可以在 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 空闲事件相同的限制;如果 Maya 很忙,他们就不会开火。

关于timer - 如何定期执行 Maya MEL 过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21164697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com