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)


On Sat, May 28, 2011 at 10:15 AM, Michiel Duvekot <[email protected]>wrote:

> // assuming you've selected a face
> sel = cmds.ls(sl=True)
> cmds.hyperShade( shaderNetworksSelectMaterialNodes=True )
> print "%s -> %s" % (sel[0], cmds.ls(sl=True)[0])
> cmds.select(sel, replace=True)
>
>
> On May 27, 2:23 pm, MaloW <[email protected]> wrote:
> > Hi, I'm working on creating an .obj-exporter as a part of a school
> > project using MEL, Python and PyMEL. I've got it working great, but
> > right now it can't export several materials for 1 object. My teacher
> > wasn't quite sure how to do this either but told me that I could ask
> > here.
> > How can I from a face, and not from the object, find out which
> > material is connected to it, so that I can export the materials per-
> > face and not per-object? I've tried looking at the documentation of
> > PyMEL as well as using dir() inside maya on a face, but I found
> > nothing that I thought could be of use.
> > Any help is appreciated, thanks.
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>



-- 
Martin La Land Romero
www.martinromerovfx.com
http://martinromerovfx.blogspot.com/
[email protected]
(415)261-2172

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to