Maya(Python):在模块中运行条件命令和scriptJob命令 [英] Maya (Python): Running condition command and scriptJob command from within a module

查看:177
本文介绍了Maya(Python):在模块中运行条件命令和scriptJob命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个UI工具,该工具将在Maya启动期间加载,并在VRay初始化后执行一些模块(否则将引发错误).

我的更广泛问题的建议此处使我尝试了condition和scriptJob命令.

下面的listener.py代码在Maya的脚本编辑器中运行时有效,但是当我导入侦听器模块并使用launcher.py代码运行它时,出现此错误:

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

请注意,由于condition命令需要mel命令语法(似乎是一个错误),因此仅调用普通函数是行不通的,并且会出现无法找到过程的错误). /p>

这里是听众:

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

这是启动器:

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

解决方案

尝试一下,

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

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)

解决方案

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

这篇关于Maya(Python):在模块中运行条件命令和scriptJob命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆