Maya:将脚本推迟到注册VRay之后? [英] Maya: Defer a script until after VRay is registered?
问题描述
我正在尝试延迟部分管道工具(在Maya启动期间运行)在注册VRay之后才能运行.
I'm trying to delay a part of my pipeline tool (which runs during the startup of Maya) to run after VRay has been registered.
我目前正在像这样在userSetup.py中延迟工具的初始化:
I'm currently delaying the initialization of the tool in a userSetup.py like so:
def run_my_tool():
import my_tool
reload(my_tool)
mc.evalDeferred("run_my_tool()")
我已经尝试在工具中使用evalDeferred来延迟render_settings脚本的执行,但是在注册VRay之前,它一直在运行.关于如何为VRay注册事件创建侦听器的任何想法,或者是什么事件?谢谢!
I've tried using evalDeferred within the tool to delay the execution of the render_settings script, but it keeps running before VRay has been registered. Any thoughts on how to create a listener for the VRay register event, or what event that is? Thanks!
编辑:
提出了一个新主题,以弄清楚如何正确使用theodox的condition/scriptJob命令建议
Made a new topic to figure out how to correctly use theodox's condition/scriptJob commands suggestion here.
推荐答案
Uiron在tech-artists.com上向我展示了如何正确执行此操作.这是
Uiron over at tech-artists.com showed me how to do this properly. Here's a link to the thread
这是uiron的帖子:
Here's the post by uiron:
除非必要,否则不要将python代码作为字符串传递.无论何时接受python回调(在Maya的api中不是处处都是,但在大多数地方都可以),请尝试以下方法之一:
"don't pass the python code as string unless you have to. Wherever a python callback is accepted (that's not everywhere in Maya's api, but mostly everywhere), try one of these:
# notice that we're passing a function, not function call
mc.scriptJob(runOnce=True, e=["idle", myObject.myMethod], permanent=True)
mc.scriptJob(runOnce=True, e=["idle", myGlobalFunction], permanent=True)
# when in doubt, wrap into temporary function; remember that in Python you can
# declare functions anywhere in the code, even inside other functions
open_file_path = '...'
def idle_handler(*args):
# here's where you solve the 'how to pass the argument into the handler' problem -
# use variable from outer scope
file_manip_open_fn(open_file_path)
mc.scriptJob(runOnce=True, e=["idle", idle_handler], permanent=True)
"
这篇关于Maya:将脚本推迟到注册VRay之后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!