Importing OBJ file to maya scene (MEL/Python)

2019-06-14 01:21发布

I am working on a script in which I need to import an external OBJ file. I have been reading and I think that should be done using the file command. I go to the maya documentation and find no clear examples about using it. What arguments should I pass in order to do that?

I have seen an example in MEL which is in this thread: http://forums.cgsociety.org/showthread.php?t=144296

file -import -type "OBJ" -options "mo=1" -pr $sourceFiles[$x];

Furthermore there should be a useful path for maya to go and collect the OBJ item, where would it be? Should I write an environment variable or something in order to query the location of the OBJ so that maya can pick it from there and bring it to the scene?

Thanks guys.

2条回答
淡お忘
2楼-- · 2019-06-14 02:06

You need to enable the objexport.mll plugin in your plugin manager to make the obj file type available, then what you have should work. You should check the workspace in any empty mscene to see where maya is looking for scene and data files.

查看更多
地球回转人心会变
3楼-- · 2019-06-14 02:20

I'm not sure if you found the file command docs here: File command, however there is loads of info on it!

To my understanding, you want to import a series of obj's from a source directory, forgive me if I'm wrong in but that's how I've interpreted your question.

import maya.cmds as cmds

pathOfFiles = "/path/to/folder/containing/objs/"
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)

What we're doing here, is pointing to a path, searching for a file type in that path and than importing them once they're found.

Hope this helps

查看更多
登录 后发表回答