Maya: Defer a script until after VRay is registered?

a 夏天 提交于 2019-12-25 04:27:50

问题


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.

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()")

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!

EDIT:

Made a new topic to figure out how to correctly use theodox's condition/scriptJob commands suggestion here.


回答1:


Uiron over at tech-artists.com showed me how to do this properly. Here's a link to the thread

Here's the post by uiron:

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

"



来源:https://stackoverflow.com/questions/38601706/maya-defer-a-script-until-after-vray-is-registered

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!