/* Display Layers to txt file V 0.75 Sorts and prints Layers to external .txt file within the directory of the current Maya file */ /*-------------------------------------------------------------------------------------- File name extractor --------------------------------------------------------------------------------------*/ global proc string filepart( string $path ) // Setting up Directories /* Extracts the name of the current open Maya file. Input: e.g. "D:/projects/default/scenes/myScene.mb" Result: e.g. "myScene.mb" Filepath can be delimited with either slash ("/" or "\") */ { string $filepart = match( "[^/\\]*$", $path ); return $filepart; } /*-------------------------------------------------------------------------------------- File Path extractor --------------------------------------------------------------------------------------*/ global proc string pathpart( string $path ) /* Extracts the path out of the absolute filepath of the current open Maya file. Input: e.g. "D:/projects/default/scenes/myScene.mb" Result: e.g. "D:/projects/default/scenes" Note: Requires that the filepath be delimited with _forward_ slashes ("/") */ { string $dir = match( "^.*/", $path ); int $sz = size( $dir ); /* Strip off trailing '/' */ if ( ( $sz > 1 ) && ( substring( $dir, $sz, $sz ) == "/" ) ) { $dir = substring( $dir, 1, ($sz - 1) ); } return $dir; } /*-------------------------------------------------------------------------------------- Layer name File Output --------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------- Prompt for DisplayLayers or Render Layers ---------------------------------------------------------------------------------------*/ global proc string userPrompt() { string $returnVal = `confirmDialog -title "Export Display/Render Layers as a text file" -message "Would you like to Export the Display Layers or Render Layers as a Text File?" -button "Display Layers" -button "Render Layers" -button "I'm not sure" -defaultButton "Display Layers" -cancelButton "I'm not sure" -dismissString "I'm not sure"`; return $returnVal; } /*--------------------------------------------------------------------------------------- Prompt for DisplayLayers or Render Layers ---------------------------------------------------------------------------------------*/ string $fullpath = `file -q -loc`; string $file = filepart( $fullpath ); string $directory = pathpart( $fullpath ); string $projPath = `file -q -loc`; string $userInput = `userPrompt`; string $selectionSyntax; string $input; if ($userInput == "Render Layers") { $selectionSyntax = "renderLayer"; $input = "Render_Layer"; } else if ($userInput == "Display Layers") { $selectionSyntax = "layer"; $input = "Display_Layer"; select -r ($selectionSyntax + "Manager"); string $layerManager[] = `ls -sl`; string $layer[] = `listConnections $layerManager`; // select -r $layer; string $path = ($projPath + "_" +$input + "_List.txt"); int $fileId = fopen($path, "w"); int $layerCheck = size ($layer)-1; int $intDispOrder[] = {0}; int $intDispOrderSize; int $i=1; // fprint($fileId, "\r\n -=Beginning of Layers=- \r\n"); /*-------------------------------------------------------------------------------------- Testing Code Area --------------------------------------------------------------------------------------*/ // print $intDispOrder; // print $intDispOrder[6];print $intDispOrder[7];print $intDispOrder[8]; // print $intDispOrder; $i=1; while($i<=$layerCheck) { select $layer[$i]; $intDispOrder[$i] = `getAttr ($layer[$i] +".displayOrder")`; $i++; } $i=1; print $intDispOrder; // int $intDispOrderSize; int $intDispOrder[] = `sort $intDispOrder`; int $intDispOrderSize = size ($intDispOrder) -1; fprint($fileId, "\r\n \r\n -=Beginning of " +$input+ " Layers=- \r\n"); // potentially dangerous loop will keep increasing file size forever. $j=$intDispOrderSize; while($j >= 1) { $k=1; while ($k <= $layerCheck) { int $currentDispOrder = `getAttr ($layer[$k] + ".displayOrder")`; if ($intDispOrder[$j] == $currentDispOrder) { fprint($fileId, "\r\n" + $layer[$k]) /* + ".displayOrder " + $currentDispOrder)*/; $k++; } else { $k++; } } $j--; } fprint($fileId, "\r\n \r\n -=End of Layers=-"); fclose $fileId; print ("A "+$input+" list "+ $file +$input+"_List.txt was output to " + $directory); } else { warning "user is confused and should take a break"; } /*-------------------------------------------------------------------------------------- Idea for making this work -------------------------------------------------------------------------------------- get the list of layers get the display order number on all the layers find the highest number on the display order and run a loop that many times loop and check from 1 to highest number print it if it's next in line. */