My tool exports the entire scene with all the textures to a new location, perhaps it has some handy line or lines that can help you out!
import maya.cmds as cmds
import os
import shutil
def AskUserForSaveLocation():
"""
This function asks the user for the new location of the .mb, .ma file, the user only needs to provide a direction.
"""
#newLocation ='C:\Users\FFION2\Desktop\GDC_VFX_CLASS' #hardcoded > enter your target directory.
multipleFilters = "Maya Files (*.ma *.mb);;Maya ASCII (*.ma);;Maya Binary (*.mb);;All Files (*.*)"
newLocation = cmds.fileDialog2(fileFilter=multipleFilters, fileMode=2, dialogStyle=2)
print (newLocation, "choosen directory")
return newLocation[0]
def copyToNewLocation(srcFiles, destDirectory):
"""
This function checks the for the current location of the file. It also copies each one of the assets to a new directory specified by the user.
"""
#It goes trough each texture as well as the maya file and place them in the new location.
for i in srcFiles:
print(i, "Got transferred")
shutil.copy(i, destDirectory )
def AskAndCopyCurrentSceneToNewDirectory():
"""
This function creates a window with a button. It also asks the user to enter a new directory and copies the maya file as well as the teuxtures to the new directory.
"""
#Location of the current maya scene.
mySceneAssets = cmds.file( q=True, l=True, loc=True )
newLocation = AskUserForSaveLocation()
#call fucntion copyToNewLocation.
copyToNewLocation(mySceneAssets, newLocation)
mr_copyNewLocUI = ''
if cmds.window(mr_copyNewLocUI, exists= True):
cmds.deleteUI(mr_copyNewLocUI)
else:
mr_copyNewLocUI = cmds.window(widthHeight = (357, 139), title = 'mr_CopyAllToNewLocation', mxb = False, mnb = False)
mainCol = cmds.columnLayout( adj = True)
cmds.rowColumnLayout( numberOfColumns=2, columnAttach=(1, 'right', 0), columnWidth=[(1, 100), (2, 250)] )
#Create a menuBar with menuItems
cmds.text( label='' )
currDirBtm = cmds.button(label= 'ExportAllTextures/MayaFile', command = 'AskAndCopyCurrentSceneToNewDirectory()' )
#Shows the window.
cmds.showWindow(mr_copyNewLocUI)
--
Martin La Land Romero
www.martinromerovfx.comhttp://martinromerovfx.blogspot.com/
martin...@gmail.com(415)261-2172