這看起來像一個有趣的挑戰做,所以這是我嘗試在回答它:
import maya.cmds as cmds
import glob
#1. Import an individual OBJ file at once
def importFile(i):
cmds.file(i, i=True, groupReference=True, groupName="myobj")
#2. Move and rotate the imported file
def moveFile():
cmds.select("myobj")
# Add the X,Y,Z cordinates to change scale, translate and rotate below
cmds.scale(1,1,1)
cmds.move(0,0,0)
cmds.rotate(0,90,0)
#3. Apply a Material already created in Maya
def materialFile():
cmds.select("myobj")
myMaterial = "lambert2" + "SG" #replace lambert2 with your material
cmds.sets(forceElement=myMaterial)
#4. Render
def renderFile(i):
cmds.setAttr("defaultRenderGlobals.imageFilePrefix", i, type="string")
cmds.render(batch=True)
#5. Delete the imported file
def deleteFile():
cmds.select("myobj")
cmds.delete()
# Add the path to your obj files. Make sure to leave the /*.obj at the end
myglob = glob.glob("/Users/OSX/Desktop/objs/*.obj")
for i in myglob:
importFile(i)
moveFile()
materialFile()
renderFile(i)
deleteFile()
因爲你的個人事情的清單,你需要的腳本做我已經把你列表中的每個要求分成它自己的功能。這應該使腳本更加模塊化,並且希望易於編輯和重用。
Python對於這類任務的工作要好得多,因爲MEL沒有函數,而是具有像函數一樣工作的過程,但從我所經歷的過程中不能很好地工作。
你好K先生,謝謝你的回答。這似乎在我改變了一些變量後正在工作。但是,有些問題我無法修復。 首先,它將圖像保存在放置obj的相同文件夾中,但無法打開。只有文件爲png和exr。 另外,它不適用該材料。將變量myMaterial更改爲在Maya中創建的變量,但仍然沒有得到它。 如何應用多種材質?物體需要兩種材料。 如何設置多個渲染相機? 歡呼聲 – jpits
嗨@ Mr-k我有一個問題,它只是將一個blin着色器應用到整個作品中,而沒有更多。我需要應用Maxwell Render materiales並將maxwell設置爲渲染器。 – jpits