'''
massExport.py v1.0
Author: Nate Lang
web: natelang3d.com
Install:
Copy this file into your maya scripts folder
------Copy below code into a python shelf button------
import massExport
massExport.massExportWindow()
------------------------------------------------------
Use:
Creates a UI that allows you to export multiple files
individually at the same time based on the selected settings.
'''
from maya import cmds
from functools import partial
#------------------------------
# Entrance Proc + Starts UI
#------------------------------
def massExportWindow():
exportWindow = 'exportWindow'
if cmds.window(exportWindow, exists=True):
cmds.deleteUI(exportWindow)
if cmds.windowPref(exportWindow, exists=True):
cmds.windowPref(exportWindow, remove=True)
winWidth = 550
winHeight = 100
cmds.window(exportWindow, width=winWidth, height=winHeight, sizeable=False, menuBar=True, title="massExport_v1.0")
mainLayout = cmds.frameLayout(borderVisible=True, borderStyle="etchedIn", labelVisible=0)
mainForm = cmds.formLayout("mainForm")
#fields inside window
outputText = cmds.text(label='Save Location:')
outputField = cmds.textFieldGrp(columnWidth=[1,350])
outputButton = cmds.button(label='Browse...', command=partial(getOutputLoc, outputField))
fileTypeText = cmds.text(label='File Type:')
fileTypeField = cmds.checkBoxGrp(numberOfCheckBoxes=3, labelArray3=['obj','ascii','binary'])
#make bottom buttons
exportButton = cmds.button(label='Export', width=150, command=partial(beginExport, outputField, fileTypeField))
cancelButton = cmds.button(label='Cancel', width=150, command=partial(deleteExportWindow, exportWindow))
#pass field names to be moved into place
editForm(mainForm, outputText, outputField, outputButton, fileTypeText, fileTypeField, exportButton, cancelButton, winWidth)
cmds.showWindow(exportWindow)
#------------------------------
# Move UI elements into correct positions
#------------------------------
def editForm(mainForm, outputText, outputField, outputButton, fileTypeText, fileTypeField, exportButton, cancelButton, winWidth):
#place text
cmds.formLayout(mainForm, edit=True, attachForm=[(outputText, "left", 20), (outputText, "top", 20)])
cmds.formLayout(mainForm, edit=True, attachForm=[(fileTypeText, "left", 20), (fileTypeText, "top", 40)])
#place fields
cmds.formLayout(mainForm, edit=True, attachForm=[(outputField, "left", 120), (outputField, "top", 15)])
cmds.formLayout(mainForm, edit=True, attachForm=[(outputButton, "top", 15)], attachControl=[(outputButton, "left", 0, outputField)])
cmds.formLayout(mainForm, edit=True, attachForm=[(fileTypeField, "top", 40)], attachControl=[(fileTypeField, "left", 28, outputText)])
#place ok + cancel buttons
sep = cmds.separator(width=winWidth, style='in' )
cmds.formLayout(mainForm, edit=True, attachControl=[(sep, "top", 5, fileTypeField)])
cmds.formLayout(mainForm, edit=True, attachForm=[(exportButton, "left", 120)], attachControl=[(exportButton, "top", 1, sep)])
cmds.formLayout(mainForm, edit=True, attachControl=[(cancelButton, "top", 1, sep), (cancelButton, "left", 1, exportButton)])
#------------------------------
# Where you will save your new files
#------------------------------
def getOutputLoc(outputField, *args):
saveLoc = cmds.fileDialog2(caption='Save Location', fileMode=3)
saveDirectory = str(saveLoc[0])
cmds.textFieldGrp(outputField, edit=True, text=saveDirectory)
#------------------------------
# Begins the export process when the ok button is pressed
#------------------------------
def beginExport(outputField, fileTypeField, *args):
#get selected object names
newExportList = cmds.ls(selection=True)
catchIfChecked = cmds.checkBoxGrp(fileTypeField, valueArray3=True, query=True)
#if the checkbox was selected, export selected file type
for eachObj in newExportList:
if catchIfChecked[0] == True:
exportAsObj(outputField, eachObj)
if catchIfChecked[1] == True:
exportAsAscii(outputField, eachObj)
if catchIfChecked[2] == True:
exportAsBinary(outputField, eachObj)
#------------------------------
# Delete's the UI
#------------------------------
def deleteExportWindow(exportWindow, *args):
cmds.deleteUI(exportWindow)
#------------------------------
# Export procedures:
#------------------------------
def exportAsObj(outputField, objToExport):
exportLoc = cmds.textFieldGrp(outputField, text=True, query=True)
cmds.select(clear=True)
cmds.select(objToExport)
newFileName = exportLoc +'/'+ objToExport
cmds.file(newFileName, force=True, typ='OBJexport', preserveReferences=True, exportSelected=True)
#cmds.file(newFileName, force=True, typ='OBJexport', preserveReferences=True, exportSelected=True, op="groups=0; ptgroups=0; materials=0; smoothing=0; normals=0")
def exportAsAscii(outputField, objToExport):
exportLoc = cmds.textFieldGrp(outputField, text=True, query=True)
cmds.select(clear=True)
cmds.select(objToExport)
newFileName = exportLoc +'/'+ objToExport
cmds.file(newFileName, force=True, typ='mayaAscii', preserveReferences=True, exportSelected=True)
#cmds.file(newFileName, force=True, typ='mayaAscii', preserveReferences=True, exportSelected=True, op="groups=0; ptgroups=0; materials=0; smoothing=0; normals=0")
def exportAsBinary(outputField, objToExport):
exportLoc = cmds.textFieldGrp(outputField, text=True, query=True)
cmds.select(clear=True)
cmds.select(objToExport)
newFileName = exportLoc +'/'+ objToExport
cmds.file(newFileName, force=True, typ='mayaBinary', preserveReferences=True, exportSelected=True)
#cmds.file(newFileName, force=True, typ='mayaBinary', preserveReferences=True, exportSelected=True, op="groups=0; ptgroups=0; materials=0; smoothing=0; normals=0")