fileDialog2

350 views
Skip to first unread message

Alexivan

unread,
May 19, 2011, 8:18:04 AM5/19/11
to python_inside_maya
can anyone show some examples for creating custom options inside
fileDialog2

Tim

unread,
May 25, 2011, 9:02:36 AM5/25/11
to python_inside_maya
Here is one in MEL. The UI is just copy/pasted from the frameLayout
example in the doc's, except that it tracks one of the int sliders
with an optionVar so it will remember the value it was set to last.


global proc MyOptionsUISetup(string $parent)
{
setParent $parent;

columnLayout -adjustableColumn true;
frameLayout -label "Buttons"
-borderStyle "in";
columnLayout;
button;
button;
button;
setParent ..;
setParent ..;
frameLayout -label "Scroll Bars"
-borderStyle "out";
columnLayout;
intSlider -min -100 -max 100 -value 0 -step 1 MyIntSlider;
intSlider;
intSlider;
setParent ..;
setParent ..;
frameLayout -label "Fields"
-borderStyle "etchedIn";
columnLayout;
intField;
intField;
intField;
setParent ..;
setParent ..;
frameLayout -label "Check Boxes"
-borderStyle "etchedOut";
columnLayout;
checkBox;
checkBox;
checkBox;
setParent ..;
setParent ..;
}

global proc MyOptionsUIInitValues(string $parent, string $filterType)
{
setParent $parent;

print ("Current file filter: " + $filterType + "\n");

// Probably make sure optionVar's or whatever are initialized here...
if (!`optionVar -exists defaultFileOpenType`)
{
optionVar -intValue MyIntSliderOption 0;
}

int $intValue = `optionVar -query MyIntSliderOption`;

// Set all the values of the controls...
intSlider -edit -value $intValue MyIntSlider;
}

global proc MyOptionsUICallback(string $parent)
{
setParent $parent;

// When the UI is going away we usually save the state in optionVar's

int $intValue = `intSlider -query -value MyIntSlider`;
optionVar -intValue MyIntSliderOption $intValue;
}

global proc MyCurrentFileTypeOption(string $parent, string
$filterType)
{
print ("File filter switched to: " + $filterType + "\n");
}

global proc MySelectionChangedCallback(string $parent, string
$selection)
{
print ("User selected: " + $selection + "\n");
}

global proc customOptions()
{
string $file[] = `fileDialog2
-returnFilter 1
-caption "Open"
-fileMode 1
-okCaption "Open"
-optionsUICreate "MyOptionsUISetup"
-optionsUIInit "MyOptionsUIInitValues"
-selectionChanged "MySelectionChangedCallback"
-optionsUICommit "MyOptionsUICallback"
-fileTypeChanged "MyCurrentFileTypeOption"
-fileFilter "Maya Scenes (*.ma *.mb);;Maya ASCII (*.ma);;Maya
Binary (*.mb);;All Files (*)"
-selectFileFilter "Maya Scenes"`
;

int $len = size($file);
if( $len > 0 && $file[0] != "" )
{
string $path = fromNativePath($file[0]);
print ("File: " + $path + "\n");
}
}

Martin La Land Romero

unread,
May 25, 2011, 11:24:30 AM5/25/11
to python_in...@googlegroups.com
Here is example of mine!



    import maya.cmds as cmds
   
   
    def getStats():
   
        #List all the geometry in the scene.
        mySel = cmds.ls( geometry=True )
        #List the path of all the textures in the scene.
        texturesPath = cmds.ls(type = "file")
        #List the total amount of textures in the scene.
        numTextures = len(cmds.ls(type = "file"))
        #Gives the total polyCount.
        totalPolyCount = cmds.polyEvaluate(mySel, face = True)
       
        #Goes though each texture and returns their fullpath.
        #for texture in texturesPath:
            #print(cmds.getAttr (texture + ".fileTextureName"))
       
        #print out the total amount of polys in the scene.
        #print('The scene has a total of: ' +  str(totalPolyCount) + '  ' + 'polys' )
       
        #return a dictionary of the tottal amount of textures and polys in the scene.
        return {
            'totalPolys' : totalPolyCount,
            'totalTextures' : numTextures,
        }
   
   
      
    #Ask the user for the location fo the maya scene.
    def AskUserForFilename():
        filename = cmds.fileDialog2(fileMode=1, caption="Import scene")
        cmds.file( filename[0], i=True )
   
    #Get polycount function.
    def getPolyCount(polys):
        totalPolyCount = polys
       
   
    #Get texturecount funcion.
    def getNumTextures(textures):
        numTextures = textures
        
   
    #Open a text file, write on it and close it.
    def saveStatsToFile(filename, stats):
   
        totalPolyCount = stats
        fileHandle = open (filename, 'w')
        fileHandle.write (filename )
        fileHandle.close()
        return filename, stats
   
   
    #Get all the stats and save them in a text file.
    def GetSceneStatsAndSaveToFile(stats):
        AskUserForFilename()
        totalPolyCount = stats
        return {
            'CollectedStats': getStats(),
            'TextFileCreated': saveStatsToFile('stats.txt', str(stats),)
        }
   
    #Final Everything.
    GetSceneStatsAndSaveToFile(3)







--
Martin La Land Romero
www.martinromerovfx.com
http://martinromerovfx.blogspot.com/
martin...@gmail.com
(415)261-2172

johnvdz

unread,
May 27, 2011, 11:31:34 PM5/27/11
to python_in...@googlegroups.com
hi all,

just downloaded the hotfix for maya 2012 and apparently there is an API
2 but it true AutoDesk style there is no Docs on whats changed , anyone
know what they have changed...? will my old API 1 stuff work?

john

Paul Molodowitch

unread,
May 29, 2011, 10:06:38 PM5/29/11
to python_in...@googlegroups.com
there are docs, you just need to download them separately.

...and yes, the python 1.0 api still works.  all the new stuff is in it's own module, maya.api

- Paul

Reply all
Reply to author
Forward
0 new messages