// Copyright (C) 1997-2014 Autodesk, Inc., and/or its licensors. // All rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files contain unpublished // information proprietary to Autodesk, Inc. ("Autodesk") and/or its licensors, // which is protected by U.S. and Canadian federal copyright law and by // international treaties. // // The Data is provided for use exclusively by You. You have the right to use, // modify, and incorporate this Data into other products for purposes authorized // by the Autodesk software license agreement, without fee. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. AUTODESK // DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES // INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF NON-INFRINGEMENT, // MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, OR ARISING FROM A COURSE // OF DEALING, USAGE, OR TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS // LICENSORS BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL, // DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK AND/OR ITS // LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY OR PROBABILITY OF SUCH DAMAGES. // // // Bonus Tools Pattern Rename V1.02 // 27.1.2011 // (c) Autodesk 2011 // // uses a list of patterns to remove or replace in object names // proc string[] standardWindow( string $windowName, string $title, string $buttons[]) { // this proc creates a standard window with a columnLayout and some button below // if $windowName is empty, a new window will be created (otherwise the existing window is shown // // it returns an array with: // - the UI name of the window // - the UI name of the columnLayout // - the names of the buttons // // The window is NOT shown, so that the contents can be added before the window appears global string $PRlistResultsUI; if (!size($buttons)) error "The Window should have at least one Button"; string $result[]; if (!size($windowName)) $windowName = `window -w 406 -h 655 -title $title`; else if (`window -exists $windowName`) { showWindow $windowName; return { $windowName } ; } else window -w 406 -h 655 -title $title $windowName; $result[0] = $windowName; $form = `formLayout -nd 100`; $tab = `tabLayout -tv 0 -scr 0 -cr 1`; // fuer ein saubers resize der children muss -scr auf 0 stehen !! $form2 = `formLayout -nd 100`; $result[1] = `columnLayout -adj true`; setParent $form2; $t = `text -label "Resulting Names"`; $PRlistResultsUI = `textScrollList`; formLayout -edit -attachForm $result[1] "top" 0 // the columnLayout -attachForm $result[1] "left" 0 -attachForm $result[1] "right" 0 -attachNone $result[1] "bottom" -attachControl $t "top" 0 $result[1] // the text above the results list -attachForm $t "left" 5 -attachForm $t "right" 5 -attachNone $t "bottom" -attachControl $PRlistResultsUI "top" 0 $t // the results list -attachForm $PRlistResultsUI "left" 0 -attachForm $PRlistResultsUI "right" 0 -attachForm $PRlistResultsUI "bottom" 0 $form2; setParent $form; $sep = `separator -h 10`; for ( $b in $buttons ) $result[size($result)] = `button -label $b`; formLayout -edit -attachForm $tab "top" 10 // the tabLayout -attachForm $tab "left" 5 -attachForm $tab "right" 5 -attachControl $tab "bottom" 5 $sep -attachNone $sep "top" // the separator -attachForm $sep "left" 5 -attachForm $sep "right" 5 -attachControl $sep "bottom" 5 $result[2] $form; int $last = size($result) - 1; // attach the first button at left and bottom - and the last at right and bottom // if its only one button, then its completely attached formLayout -edit -attachNone $result[2] "top" -attachForm $result[2] "left" 5 -attachForm $result[2] "bottom" 5 -attachNone $result[$last] "top" -attachForm $result[$last] "right" 5 -attachForm $result[$last] "bottom" 5 $form; int $gapStep = 100 / size($buttons); for ( $i=3 ; $i3) $iconText = substring( $text, 1, 4); else $iconText = $text; if ($iconText=="") $iconText = "PatR"; } else return; // User hit Cancel int $maxIter = `intFieldGrp -q -v1 $PRmaxIterUI`; string $prefix = `textFieldGrp -q -text $PRprefixUI`; string $shelfScript = "// Pattern Rename 1.02 (c) Autodesk 2011 - Roland Reyer\n// " + encodeString($text) + "\n\n"; $shelfScript += "source patternRename.mel;\n"; $shelfScript += "{\nstring $prefix = \"" + $prefix + "\";\n"; $shelfScript += "int $maxIter = " + $maxIter + ";\n"; $shelfScript += "string $search[] = {"; for ( $i=0 ; $i " + $PRreplace[$i]) $PRlistSubsUI; else textScrollList -e -a ($PRsearch[$i]) $PRlistSubsUI; } int $totalItems = `textScrollList -q -numberOfItems $PRlistSubsUI`; if ($totalItems) textScrollList -e -selectIndexedItem (min($totalItems, ($select+1))) $PRlistSubsUI; } global proc patternRenameUpdate() { global string $PRobjects[]; global string $PRsearchUI; // UI name of the input field global string $PRsearch[]; // list of strings to search global string $PRreplaceUI; // UI name of the input field global string $PRreplace[]; // list of strings to replace global string $PRlistResultsUI; global string $PRmaxIterUI; global string $PRprefixUI; int $maxIter = `intFieldGrp -q -v1 $PRmaxIterUI`; string $prefix = `textFieldGrp -q -text $PRprefixUI`; $obj = $PRobjects; string $newSearch = `textFieldGrp -q -text $PRsearchUI`; string $newReplace = `textFieldGrp -q -text $PRreplaceUI`; string $orgSearch[] = $PRsearch; string $orgReplace[] = $PRreplace; if ($newReplace=="" || isValidString( $newReplace, "([a-zA-Z0-9_])*")) { // no spaces allowed if ($newSearch != "") { for ( $i=0 ; $i-1 ; $i-- ) { textScrollList -e -removeIndexedItem $sel[$i] $PRlistSubsUI; stringArrayRemoveAtIndex( $sel[$i]-1, $PRsearch); stringArrayRemoveAtIndex( $sel[$i]-1, $PRreplace); } textFieldGrp -e -text "" $PRsearchUI; textFieldGrp -e -text "" $PRreplaceUI; patternRenameUpdate(); } global proc patternRenameAdd() { global string $PRobjects[]; global string $PRsearchUI; // UI name of the input field global string $PRsearch[]; // list of strings to search global string $PRreplaceUI; // UI name of the input field global string $PRreplace[]; // list of strings to replace global string $PRlistSubsUI; global string $PRlistResultsUI; string $newSearch = `textFieldGrp -q -text $PRsearchUI`; string $newReplace = `textFieldGrp -q -text $PRreplaceUI`; if ( $newReplace=="" || isValidString( $newReplace, "([a-zA-Z0-9_])*")) { // no spaces allowed if ($newSearch == "") return; for ( $i=0 ; $i1) $namespaces[$i] = substring( $objects[$i], 1, size($objects[$i]) - size($tmp[$anz-1]) - 1); else $namespaces[0] = ""; // the last token is the object name $objects[$i] = $tmp[$anz-1]; } } global proc patternRenameReload() { global string $PRobjects[]; global string $PRnamespaces[]; patternRenameLoadSelected( $PRobjects, $PRnamespaces); /* $PRobjects = `ls -sl`; clear $PRnamespaces; // now cut off ALL namespaces for ( $i=0 ; $i1) $PRnamespaces[$i] = substring( $PRobjects[$i], 1, size($PRobjects[$i]) - size($tmp[$anz-1]) - 1); else $PRnamespaces[0] = ""; // the last token is the object name $PRobjects[$i] = $tmp[$anz-1]; } */ patternRenameUpdate(); } global proc patternRenameGo() { global string $PRobjects[]; global string $PRnamespaces[]; global string $PRsearch[]; // list of strings to search global string $PRreplace[]; // list of strings to replace global string $PRmaxIterUI; global string $PRprefixUI; int $maxIter = `intFieldGrp -q -v1 $PRmaxIterUI`; string $prefix = `textFieldGrp -q -text $PRprefixUI`; $obj = $PRobjects; $obj = doPatternRename( $obj, $PRsearch, $PRreplace, $prefix, $maxIter); for ( $i=0 ; $i