// =========================================================================== // 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: 2007 // // Description: // Given a node, find one of type $type that is the closest traversal in // either its past or future. While doing the search, prune any nodes that can // only be reached by visiting a node of type specified in $pruneTypes // // global proc string findTypePrune( string $obj, // Starting node string $type, // Type to find string $pruneTypes[] ) // prune types // // Description: // Given a node, find one of type $type in either its past or future. // While doing the search, prune any nodes that can only be reached by // visiting a node of type specified in $pruneTypes // { // In the case that the object type exists in both past and future // find the one that is fewer connections away. Technically, this may not // be quite true, depending on the level of branching of past vs future, // but close enough. // string $past[] = pruneSearch( $obj, false, $pruneTypes ); string $pastObjs[] = `ls -type $type $past`; string $future[] = pruneSearch( $obj, true, $pruneTypes ); string $futureObjs[] = `ls -type $type $future`; int $numPast = size( $pastObjs ); int $numFuture = size( $futureObjs ); if($numPast>0){ if( $numFuture > 0) { int $i; int $min = size($future); if( size($past) < $min ){ $min = size($past); } for( $i = 0; $i < $min; $i++){ if( $past[$i] == $pastObjs[0] ){ return $pastObjs[0]; } if( $future[$i] == $futureObjs[0] ){ return $futureObjs[0]; } } } else { return $pastObjs[0]; } } else if( $numFuture > 0) { return $futureObjs[0]; } return(""); }