簡體   English   中英

在Python中從Maya運行cmd.exe命令的列表

[英]Running list of cmd.exe commands from maya in Python

我正在編寫一個maya python腳本,以將場景批量渲染為jpg,然后使用ffmpeg將其變為mov。 目前,該腳本將一串命令保存為bat文件,該文件可以正常工作,但我寧願僅從maya運行cmd.exe並執行命令列表,而無需先創建該bat。

我一直在閱讀有關“ subprocess.popen()”的信息,但我無法弄清楚如何使其遍歷每一行,運行該命令,然后在完成后移至下一個命令,即:

1)運行maya render.exe並將場景另存為jpegs

2)將ffmpeg jpgs移動

我已經縮短了目錄,但本質上是這樣的:

`C:\PROGRA~1\Autodesk\Maya2015\bin\Render.exe -r hw2 -s 100 -e 200 -of jpg -fnc 7 -x 1920 -y 1080 -rd 
"C:\RENDER" 
"C:\SCENE.ma" ffmpeg -y -r 25 -start_number 0100 -i C:\SCENE_%%04d.jpg C:\SCENE.mov

我將如何做到這一點?

謝謝!

first_process = subprocess.Popen(r'RenderCommand', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
first_out,first_err = first_process.communicate()
first_exicode = first_process.returncode
print(first_out)
if str(first_exicode) != '0':
    print(first_err)

second_process = subprocess.Popen(r'SecondCommand', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
second_out,second_err = second_process.communicate()
second_exicode = second_process.returncode
print(second_out)
if str(second_exicode) != '0':
    print(second_err)

third_process = subprocess.Popen(r'ConvertCommand', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
third_out,third_err = third_process.communicate()
third_exicode = third_process.returncode
print(third_out)
if str(third_exicode) != '0':
    print(third_err)

重要的提示:

在每個Popen()執行期間,Maya的GUI將被凍結。 這真的很不方便,特別是如果您要渲染很多幀。

我建議您將Render和Convert調用與主腳本分開,以避免發生這種情況。

您可以這樣操作:

在您的主腳本中(您將在其中調用Popen()

subprocess.Popen(r'mayapy.exe R:\\paul\\Trash\\render_and_convert.py 50 100 150', False)

該命令不會凍結Maya的GUI。 您可以將參數從主腳本傳遞到render_and_convert.py (文件路徑,開始/結束幀等)。

render_and_convert.py:

import sys
import subprocess
import maya.standalone as std
std.initialize(name='python')
import maya.cmds as cmds
import maya.mel as mel

# store the arguments in variables
first_argument  = sys.argv[1] # =50
second_argument = sys.argv[2] # =100
third_argument  = sys.argv[3] # =150

first_process = subprocess.Popen(r'RenderCommand ' + first_argument + ' ' + second_argument,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
first_out,first_err = first_process.communicate()
first_exicode = first_process.returncode
print(first_out)
if str(first_exicode) != '0':
    print(first_err)

second_process = subprocess.Popen(r'SecondCommandWithoutArgs', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
second_out,second_err = second_process.communicate()
second_exicode = second_process.returncode
print(second_out)
if str(second_exicode) != '0':
    print(second_err)

third_process = subprocess.Popen(r'ConvertCommand ' + third_argument,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
third_out,third_err = third_process.communicate()
third_exicode = third_process.returncode
print(third_out)
if str(third_exicode) != '0':
    print(third_err)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM