import maya.cmds as cmds import pymel.core as pm #Opens a new UI, whilse closing the previous one if (cmds.window("batchExporter_Window", q=True, exists=True)): cmds.deleteUI("batchExporter_Window", window=True) item = "" selectedObjs = [] selectedObjs=pm.ls(sl=1) #query output directory from UI outputDir = pm.textField("outputFileDir",query=True,text=True) #Exports all selected objects and as all file types. def exportAll(*args): for item in selectedObjs: pm.select(item) pm.cmds.file(("outputDir()" + str(item) + ".mb"), typ="mayaBinary", force=1, es=1) pm.cmds.file(("outputDir()" + str(item) + ".ma"), typ="mayaAscii", force=1, es=1) pm.cmds.file(("outputDir()" + str(item) + ".fbx"), typ="FBX export", force=1, es=1) pm.cmds.file(("outputDir()" + str(item) + ".obj"), typ="OBJexport", force=1, es=1) #Exports all selected objects and as .mb def exportMB(*args): for item in selectedObjs: pm.select(item) pm.cmds.file(("/Users/colonel/Desktop/Batch Export/" + str(item) + ".mb"), typ="mayaBinary", force=1, es=1) #Exports all selected objects and as .ma def exportMA(*args): for item in selectedObjs: pm.select(item) pm.cmds.file(("/Users/colonel/Desktop/Batch Export/" + str(item) + ".ma"), typ="mayaAscii", force=1, es=1) #Exports all selected objects and as .fbx def exportFBX(*args): for item in selectedObjs: pm.select(item) pm.cmds.file(("/Users/colonel/Desktop/Batch Export/" + str(item) + ".fbx"), typ="FBX export", force=1, es=1) #Exports all selected objects and as .obj def exportOBJ(*args): for item in selectedObjs: pm.select(item) pm.cmds.file(("/Users/colonel/Desktop/Batch Export/" + str(item) + ".obj"), typ="OBJexport", force=1, es=1) def browseDir(): outputDir = pm.promptForFolder() pm.textField("outputFileDir",edit=True,text=outputDir) #The GUI def UI(): cmds.window("batchExporter_Window", title='Batch Exporter', width=200) pm.frameLayout('', label="Batch Exporter - Select your objects first.") cmds.columnLayout( adjustableColumn=True ) cmds.button( label='Export All', command=exportAll ) cmds.button( label='Export mb', command=exportMB ) cmds.button( label='Export ma', command=exportMA ) cmds.button( label='Export fbx', command=exportFBX ) cmds.button( label='Export obj', command=exportOBJ ) #create eoutput file directory picker pm.separator(h=15,style="none") pm.text("Output file directory:",align="left");emptySpace() pm.textField("outputFileDir",w=300) pm.button( label='Choose Directory',w=20,h=20,command="browseDir()") pm.separator(h=15,style="out"); cmds.showWindow() UI()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question