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)
On Wed, May 25, 2011 at 6:02 AM, Tim <[email protected]> wrote:
> 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");
> }
> }
>
> --
> 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