【问题标题】:Exporting an OBJ file to another OBJ file using Python in Maya在 Maya 中使用 Python 将 OBJ 文件导出到另一个 OBJ 文件
【发布时间】:2015-08-19 18:24:06
【问题描述】:

我无法让导出功能正常工作,而且我确信我只是有愚蠢的语法或某处。基本上我正在打开一个 OBJ 文件,对其进行操作,然后将其保存到另一个 OBJ 文件中。一切正常,直到最终导出。关于可能的语法问题的任何想法?当我回到我的工作计算机时,如果需要,我可以从控制台提供错误反馈。感谢您的帮助!

import maya.cmds as mc
#one two skip a few
#open the file
mc.file(mayaFiles[i], open = True, force = True)
#do some things to the file
#now let's save it!
mc.select( all=True )
outputDir = mc.workspace (query = True, fileRule = True)
path =  "Users/MyName/MyPath/Object.obj"
mc.file(path,pr=1,typ="OBJexport",es=1,op="groups=0; ptgroups=0; materials=0; smoothing=0; normals=0")
print path;

编辑:经过@brycelynch 和其他人的一些想法,以及我自己的一些实验,我现在有了我的导出代码:

c.select( all=True )
outputDir = mc.workspace (query = True, dir = True) 
path = os.path.join(outputDir+"/objExp/","Object"+str(i)+".obj") 
print outputDir
mc.loadPlugin('objExport') 
mc.file(path,pr=1,typ="OBJ",es=1,op="groups=0; ptgroups=0;materials=0; smoothing=0; normals=0")

我目前得到的错误是:

Could not save file "/Users/myPath/objExp/Object0.obj

【问题讨论】:

  • 尝试全部导出而不是选择并导出选定的......?
  • 原谅我的无知,只是想验证一下,这样可以导出:mc.file(path,pr=1,typ="OBJexport",ea=True,op="groups=0 ;ptgroups=0;materials=0;smoothing=0;normals=0")

标签: python export maya .obj


【解决方案1】:

试试这个:

import maya.cmds as mc

import os.path

mc.select( all=True )
outputDir = mc.workspace (query = True, dir = True)
path = os.path.join(outputDir,"Object.obj")
print outputDir;
mc.file(path,pr=1,typ="OBJexport",es=1,op="groups=0; ptgroups=0;materials=0; smoothing=0; normals=0")
print path;

【讨论】:

  • 谢谢,Bryce - 我明天在我的代码前面时会试试这个,并将结果更新给你。
  • 我们成功了!因此,对于 typ,我发现它必须是“OBJ”(如果您还没有导入它,请运行 loadPlugin("objExport") )。现在我得到错误:
    Could not save file "/Users/myPath/objExp/Object0.obj"

    现在的代码是:

    mc.select( all=True ) <br/> outputDir = mc.workspace (query = True, dir = True) <br/> path = os.path.join(outputDir+"/objExp/","Object"+str(i)+".obj") <br/> print outputDir; <br/> mc.loadPlugin('objExport') <br/> mc.file(path,pr=1,typ="OBJ",es=1,op="groups=0; ptgroups=0;materials=0; smoothing=0; normals=0")
【解决方案2】:
#delete nondeformer history since objs can be funky
mel.eval('doBakeNonDefHistory( 1, {"prePost" });')
#make sure obj plugin is included
mc.loadPlugin('objExport')
#export that sucker
mel.eval('file -force -options "groups=1;ptgroups=1;materials=1;smoothing=1;normals=1" -type "OBJexport" -pr -ea "/Users/myane/mypath/objExp/%s.obj";'%("myFileName"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-11
    • 2016-12-26
    • 2016-02-09
    • 2020-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多