0

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

A suggestion from my broader question here has lead me to try out the condition and scriptJob commands.

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:

Error: line 1: name 'is_vray_loaded' is not defined
Traceback: (most recent call last):
    File "<maya console>", line 1, in <module>
NameError: name 'is_vray_loaded' is not defined

Note 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).

Here's the listener:

# 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()'])

Here's the launcher:

# 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)
Community
  • 1
  • 1
Mike Bourbeau
  • 481
  • 11
  • 29

1 Answers1

1

try that,

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'])
Ari Gold
  • 1,528
  • 11
  • 18
  • welcome,please read that, http://stackoverflow.com/questions/24616757/maya-python-cmds-button-with-ui-passing-variables-and-calling-a-function – Ari Gold Aug 31 '16 at 15:49
  • Thank you for the help and link! I thought it was working, but it looks like there was some variable in the cache that made it seem like it was working. I'm unable to reproduce the working results on a fresh open of Maya. – Mike Bourbeau Aug 31 '16 at 15:56
  • let me please know your solution, for the next time......the same error? – Ari Gold Aug 31 '16 at 15:59
  • If I just run your code in the script editor I get this error: `// Error: ; // // Error: Line 1.1: Syntax error //` – Mike Bourbeau Aug 31 '16 at 16:01
  • 1
    okay, can you edit the call command again like: 'python("is_vray_loaded()");') but without the () ......eg: mc.condition('vray_initialized', initialize=True, d='idle', s='python("is_vray_loaded");') – Ari Gold Aug 31 '16 at 16:03
  • That fixes the syntax error when running from the script editor, but I'm not seeing anything print when I turn on VRay. Also, when I try to use the launcher script to import the module and run it, I'm getting the same errors from my initial question. – Mike Bourbeau Aug 31 '16 at 16:11
  • can you import the "is_vray_loaded" func with import vray_listener reload(vray_listener); vray_listener.is_vray_loaded()? – Ari Gold Aug 31 '16 at 16:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/122330/discussion-between-mike-bourbeau-and-ari-gold). – Mike Bourbeau Aug 31 '16 at 17:44