从python shell运行maya [英] run maya from python shell

查看:163
本文介绍了从python shell运行maya的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有数百个maya文件必须使用一个脚本运行.所以我在想为什么我还要打扰maya,我应该可以从python shell(而不是maya的python shell,windows的python shell)进行操作

So I have hundreds of maya files that have to be run with one script. So I was thinking why do I even have to bother opening maya, I should be able to do it from python shell (not the python shell in maya, python shell in windows)

因此,想法是:

fileList = ["....my huge list of files...."]
for f in fileList:
    openMaya
    runMyAwesomeScript

我发现了:

C:\Program Files\Autodesk\Maya201x\bin\mayapy.exe
maya.standalone.initialize()

看起来好像加载了sth,因为我可以看到我的脚本是从自定义路径加载的.但是,它不会使maya.exe运行.

And it looks like it loads sth, because I can see my scripts loading from custom paths. However it does not make the maya.exe run.

任何帮助都是值得欢迎的,因为我从未做过这种Maya python外部事情.

Any help is welcome since I never did this kind of maya python external things.

P.S.使用Maya 2015和python 2.7.3

P.S. Using maya 2015 and python 2.7.3

推荐答案

您处在正确的轨道上. Maya.standalone运行无头,非GUI版本的Maya,因此非常适合批处理,但它实际上是命令行应用程序.除了缺少GUI之外,它与常规会话相同,因此您将拥有相同的python路径和

You are on the right track. Maya.standalone runs a headless, non-gui versions of Maya so it's ideal for batching, but it is essentially a command line app. Apart from lacking GUI it is the same as regular session, so you'll have the same python path and

您将需要设计批处理过程,因此它不需要任何UI交互(因此,例如,您要确保以不会向用户抛出对话框的方式保存或导出内容) .

You'll want to design your batch process so it doesn't need any UI interactions (so, for example, you want to make sure you are saving or exporting things in a way that does not throw dialogs at the user).

如果您只想使用仅命令行的Maya,则可以以交互方式运行会话:

If you just want a commandline-only maya, this will let you run an session interactively:

mayapy.exe -i -c "import maya.standalone; maya.standalone.initialize()"

如果要运行脚本,则在顶部添加import maya.standalonemaya.standalone.initialize(),然后执行您想做的任何工作.然后从命令行运行它,如下所示:

If you have a script to run instead, include import maya.standalone and maya.standalone.initialize() at the top and then whatever work you want to do. Then run it from the command line like this:

mayapy.exe "path/to/script.py"

大概您想在该脚本中包含要处理的文件列表,并使其一次只浏览一次.像这样:

Presumably you'd want to include a list of files to process in that script and have it just chew through them one at a time. Something like this:

import maya.standalone
maya.standalone.initialize()
import maya.cmds as cmds
import traceback

files = ['path/to/file1.ma'. '/path/to/file2.ma'.....]

succeeded, failed = {}

for eachfile in files:
    cmds.file(eachfile, open=True, force=True)
    try:
        # real work goes here, this is dummy
        cmds.polyCube()  
        cmds.file(save=True)
        succeeded[eachfile] = True
    except:
        failed[eachfile] = traceback.format_exc()

print "Processed %i files" % len(files)
print "succeeded:"
for item in succeeded: 
       print "\t", item

print "failed:"
for item, reason in failed.items():
    print "\t", item
    print "\t", reason

哪个应该对一堆文件进行一些操作,并报告哪些文件成功以及哪些文件由于什么原因失败

which should do some operation on a bunch of files and report which ones succeed and which fail for what reason

这篇关于从python shell运行maya的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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