Importing OBJ file to maya scene (MEL/Python)

陌路散爱 提交于 2019-12-08 11:29:49

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/21675233/importing-obj-file-to-maya-scene-mel-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!