0

I'm having trouble getting an export function to work and I'm sure I just have dumb syntax or something somewhere. Basically I'm opening an OBJ file, manipulating it, and saving it to another OBJ file. Everything works fine until the end export. Any ideas about possible syntactical issues? When I'm back at my work computer I can provide error feedback from the console if need be. Thanks for the help!

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;

Edit: After some ideas from @brycelynch and others, and some experimentation on my own, I'm now here with my export code:

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")

The error I currently get is:

Could not save file "/Users/myPath/objExp/Object0.obj
  • try export all instead of selecting and exporting selected....? – theodox Jun 04 '15 at 23:22
  • Excuse my ignorance, just want to verify, this would be export all right: mc.file(path,pr=1,typ="OBJexport",ea=True,op="groups=0; ptgroups=0; materials=0; smoothing=0; normals=0") – justinhpatterson Jun 04 '15 at 23:29

2 Answers2

0

Try this:

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;
  • Thanks, Bryce - I'll try this when I'm in front of my code tomorrow and will update you with the results. – justinhpatterson Jun 05 '15 at 01:27
  • We're getting there! So, for typ, I found it needs to be "OBJ" (and if you don't have it imported already, run `loadPlugin("objExport")` ). Now I get the error:
    `Could not save file "/Users/myPath/objExp/Object0.obj"`

    The code is now:

    `mc.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")`
    – justinhpatterson Jun 05 '15 at 16:31
0
#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"))