Model Export Script

Model Export Script

Anonymous
Not applicable
713 Views
3 Replies
Message 1 of 4

Model Export Script

Anonymous
Not applicable
I looked all through the Python API, but I can not find a way to export a model. All I want to do is be able to script saving multiple objects seperately in a single scene. Any Ideas? I know there might be a way to use mel commands in python, so I found out the script that runs when you export, so that may be the best way to go about my problem. Thanks.

pv_performAction {filename}.mb" "mayaBinary";
file -f -save -options "v=0;p=17" -type "mayaBinary";
// {filename}.mb //
// 1 //


Shawn
0 Likes
714 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
If you want to use MEL from python you could use something like this:

import maya.mel as mel
fileName = "C:/selectedObjectsExported.ma"
mel.eval("file -op \"v=0\" -typ \"mayaAscii\" -pr -es \"" + fileName + "\";")


A "better" way is to use the equivalent python "file" command:

import maya.cmds as cmds
fileName = 'C:/pythonExportSelected.ma'
cmds.file(fileName, exportSelected=1, type='mayaAscii')


Both codes will create a ".ma" file containing the selected objects from the current scene.

Hope this helps.
0 Likes
Message 3 of 4

Anonymous
Not applicable
Ok, so I got it working a while ago, but now I need to change it to loop through all my objects and save a file for each object. IE: if I have three objects, a cube, a cone, and a sphere, I want to select them all, and execute my script. I then want to save three files, cube.mb, cone.mb, and sphere.mb. In each file I only want the object that corresponds to the name. I checked the API, but it looks like there is no way to do this at the current time. Any Ideas? Is there more funtionality on the MEL side?

I just thought that I could manually select and deselect as I am looping though...keeping 2 list. One of the current object, and the other of all the objects. So i loop through all the objects, but in the loop I change my selection to the current one. That could work i guess.
0 Likes
Message 4 of 4

Anonymous
Not applicable
You pretty much got it.

i dont have my python thinking cap on, but this kinda how i would do it:


import maya.cmds as cmds
fileName = 'C:/pythonExportSelected.ma'
cmds.file(fileName, exportSelected=1, type='mayaAscii')


objects = {'ball','cube','sphere'}

for obj in objects:
fileName = 'c:/temp/'+ obj +'pyEx.ma'
cmds.select('clear?')
cmds.select(obj)
cmds.file(fileName, exportSelected=1, type='mayaAscii')


actually id write it in mel, because for me its easier and for this task python takes the same amout of time to run the commands.

hope this helps.
0 Likes