Maya (Python): Running condition command and scriptJob command from within a module
<p>I'm creating a UI tool that loads during Maya's startup, and executes some modules AFTER VRay has initialized (otherwise an error is thrown).  </p>

<p>A suggestion from my broader question <a href="http://stackoverflow.com/questions/38601706/maya-defer-a-script-until-after-vray-is-registered">here</a> has lead me to try out the condition and scriptJob commands.  </p>

<p>The listener.py code below works when run from within Maya's script editor, but when I import the listener module and run it using the launcher.py code, I get this error:</p>

<pre><code>Error: line 1: name 'is_vray_loaded' is not defined
Traceback: (most recent call last):
    File "&lt;maya console&gt;", line 1, in &lt;module&gt;
NameError: name 'is_vray_loaded' is not defined
</code></pre>

<p><strong>Note</strong> that the condition command requires a mel command syntax (seems to be a bug), so just calling the normal function doesn't work and gives an error that procedure cannot be found).</p>

<p>Here's the listener:</p>

<pre><code># vray_listener.py

import os

import maya.cmds as mc
import maya.mel as mel

vray_plugin_path_2016   = os.path.join('C:', os.sep, 'Program Files', 'Autodesk', 'Maya2016', 'vray', 'plug-ins', 'vrayformaya.mll')

#-----------------------------------------------------------------------
def is_vray_loaded():
    return mc.pluginInfo(vray_plugin_path_2016, q=1, l=True)

#-----------------------------------------------------------------------
def hey():
    print 'hey'

mc.condition('vray_initialized', initialize=True, d='idle', s='python("is_vray_loaded()");')

mc.scriptJob(ct=['vray_initialized', 'hey()'])
</code></pre>

<p>Here's the launcher:</p>

<pre><code># launcher.py

import sys

vray_listener_path = 'S:/path/to/module'

if vray_listener_path not in sys.path:
    sys.path.append(vray_listener_path)

import vray_listener
reload(vray_listener)
</code></pre>

<p>try that, </p>

<pre><code>import os
import maya.cmds as mc
import maya.mel as mel

vray_plugin_path_2016   = os.path.join('C:', os.sep, 'Program Files', 'Autodesk', 'Maya2016', 'vray', 'plug-ins', 'vrayformaya.mll')

#-----------------------------------------------------------------------
def is_vray_loaded(*args):
    return mc.pluginInfo(vray_plugin_path_2016, q=1, l=True)

#-----------------------------------------------------------------------
def hey(*args):
    print 'hey'

mc.condition('vray_initialized', initialize=True, d='idle', s=is_vray_loaded)

mc.scriptJob(ct=['vray_initialized', 'hey'])
</code></pre>

python condition maya