Import Multiple .Obj into Maya, Apply Texture and Batch

40 views
Skip to first unread message

jpi...@gmail.com

unread,
Sep 28, 2016, 3:18:21 AM9/28/16
to Python Programming for Autodesk Maya
Hi Guys,

I need to create .command file with an automatic rendering in Maya where I can import multiple Obj files, to different render layers, apply materials and create a batch render for them.

I have the following script:

import maya.cmds as cmds
import glob

def importFile(i):
cmds.file(i, i=True, groupReference=True, groupName="myobj")


def moveFile():
cmds.select("myobj")

cmds.scale(1,1,1, r=True)
cmds.move (0, 14, 0, r=True)
cmds.rotate (-90, 0, 0, r=True)


def materialFile():
cmds.select("myobj")
myMaterial = "blinn1"
cmds.sets( e=True, forceElement= myMaterial + 'SG' )


def renderFile(i):
cmds.setAttr("defaultRenderGlobals.imageFilePrefix", i, type="string")
cmds.render(batch=True)


def deleteFile():
cmds.select("myobj")
cmds.delete()


myglob = glob.glob("/Users/MyMacbook/Documents/maya/projects/default/assets/Ring exports/Obj/*.obj")

for i in myglob:
importFile(i)
moveFile()
materialFile()
renderFile(i)
deleteFile()


The problem with this script is that it applies the material to the whole obj element. I need to apply different shaders to specifit pieces on the element.

The other problem is, it renders in the UI and I need to create a bach render.

After that I need to call all of this actions from a .command file because I will go to a render farm.



I73

unread,
Oct 4, 2016, 6:57:32 PM10/4/16
to Python Programming for Autodesk Maya, jpi...@gmail.com
I don't fully understand what you're asking it's a little confusing on what you mean to specific pieces and how you're trying to achieve it. 

But I can answer your other 2 questions:
By default your renders are saved to: 
C:\Users\user\Documents\maya\projects\default\images\tmp
You can change this easily by changing your fileRule on "images" to: 
cmds.workspace(fileRule= ['images', "%s" % directoryPath])

As for batch renders please look into mayapy very easy tutorial.

Once you have the script working just paste it into your standalone python file and it will run as a process. 
Reply all
Reply to author
Forward
0 new messages