您好我有这个代码用Python将OBJ文件导入maya
**
import maya.cmds as cmds
pathOfFiles = "/Path/to/the/files/folder/"
fileType = "obj"
files = cmds.getFileList(folder=pathOfFiles, filespec='*.%s' % fileType)
if len(files) == 0:
cmds.warning("No files found")
else:
for f in files:
cmds.file(pathOfFiles + f, i=True)

**
导入该文件夹中的所有obj文件。
然而,我需要的是:
是否可以使用Python或MEL
答案 0 :(得分:0)
这看起来像是一个有趣的挑战,所以我试图回答它:
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没有功能,相反,它的程序就像功能一样,但不能从我所经历过的那样开始。