Mike Bourbeau Mike Bourbeau - 1 year ago 147
Python Question

Maya: Defer a script until after VRay is registered?

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


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!


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

Answer Source

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
mc.scriptJob(runOnce=True, e=["idle", idle_handler], permanent=True)


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download