// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // // // // Creation Date: Mar. 14, 1997 // // // // // // string[] executeForEachObject( string $inThisList[], string $thisCmd ) // // // This procedure takes a list of object names and applies the // command in "thisCmd" to each object. The object name is // substituted for a %s in the command. // // // string $inThisList[] - a list of object names to operate on // string $thisCmd - a string with %s in it. // // // An array of strings is returned containing // the names of all results from executing this command on each // applicable object. // // // // // Example 1. if "thisCmd" is a string that looks like: // string $thisCmd = "reverseCommand -ch off -rpo on %s"; // // and curve1 and curve2 are in the given list, then the commands // // that will be executed for each object will look like: // reverseCommand -ch off -rpo on curve1; // reverseCommand -ch off -rpo on curve2; // // // Example 2. if "thisCmd" is a string that looks like: // string $thisCmd = "reverseProc( true, false, %s )"; // // and curve1 and curve2 are in the given list, then the commands // // that will be executed for each object will look like: // reverseProc( true, false, "curve1" ); // reverseProc( true, false, "curve2" ); // // // Example 3. // cone; sphere; select -all; // string $cmd = "duplicate %s"; // string $itemList[] = `ls -sl`; // select -d; // string $results[] = executeForEachObject($itemList, $cmd); // // // global proc string[] executeForEachObject( string $inThisList[], string $thisCmd ) { string $listOfExecutedObjects[]; string $results[]; int $numExecutions = 0; int $numObjects = size($inThisList); if( $numObjects > 0 ) { int $i; string $tmp; for( $i=0; $i<$numObjects; $i+=1 ) { if ( "" == $inThisList[$i] ) { $tmp = `substitute "%s" $thisCmd $inThisList[$i]`; } else { $tmp = `substitute "%s" $thisCmd ("\"" + $inThisList[$i] + "\"")`; } if( !catch( $results = evalEcho( $tmp ) )) { $numExecutions ++; int $numResults = size( $results ); int $numExec = size( $listOfExecutedObjects ); for( $n = 0; $n < $numResults; $n ++ ) { $listOfExecutedObjects[$numExec + $n] = $results[$n]; } } } } return $listOfExecutedObjects; }