首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >玛雅:把脚本推迟到VRay注册之后?

玛雅:把脚本推迟到VRay注册之后?
EN

Stack Overflow用户
提问于 2016-07-27 00:00:32
回答 1查看 629关注 0票数 0

我正在尝试延迟我的管道工具的一部分(在Maya启动时运行),以便在VRay注册之后运行。

我目前正在推迟userSetup.py中工具的初始化,如下所示:

代码语言:javascript
运行
复制
def run_my_tool():
    import my_tool
    reload(my_tool)

mc.evalDeferred("run_my_tool()")

我尝试在工具中使用evalDeferred来延迟render_settings脚本的执行,但是在VRay被注册之前它一直在运行。对于如何为VRay注册事件创建侦听器,或者是什么事件,有任何想法吗?谢谢!

编辑

提出了一个新的主题,以了解如何正确使用传统的条件/脚本作业命令建议这里

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-27 00:13:48

在Techno-Arsts.com网站上,Uiron向我展示了如何正确地做这件事。这是一个链接到线程

这是uiron的帖子:

“除非有必要,否则不要将python代码作为字符串传递。无论哪里接受python回调(在Maya的api中并不是所有的地方,但大部分是在任何地方),都可以尝试其中的一个:

代码语言:javascript
运行
复制
# 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)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38601706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档