// =========================================================================== // 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: 13 April 1997 // // Procedure Name: // cycleIntermediateObjectSibling // // Description: // For the shapes under a single transform where only one is // non-intermediate object and the other ones are - "cycle" // through them so that // // Input Arguments: // modifySelection - if set, the selection list is modified // to replace previously non-intermediate object // with a new non-intermediate object. // // Return Value: // None. // proc string getTheTransform( string $item ) { string $result = $item; string $tmp[] = `ls -tr $result`; if( size($tmp) == 0 ) { $tmp = `listRelatives -p $result`; if( size($tmp) > 0 ) { $result = $tmp[0]; } } return $result; } proc string needTheLeadTransform() { string $result = ""; string $tmp[] = `ls -l -sl -tail 1 -type dagNode`; if( size($tmp) > 0 ) { $result = getTheTransform( $tmp[0] ); } else { $tmp = `ls -l -sl -tail 1`; if( size($tmp) > 0 ) { $tmp = `listRelatives -p $tmp[0]`; if( size($tmp) > 0 ) { $result = getTheTransform( $tmp[0] ); } } } return $result; } proc doModifySelection( string $oldVers, string $newVers ) { string $act[] = `ls -sl`; int $i, $n; $n = size($act); for( $i=0; $i<$n; $i+=1 ) { $act[$i] = `substitute ($oldVers +"$") $act[$i] $newVers`; $act[$i] = `substitute ($oldVers +"\\.") $act[$i] ($newVers + ".")`; } select -cl; for( $i=0; $i<$n; $i+=1 ) { select -add $act[$i]; } } global proc cycleIntermediateObjectSibling( int $modifySelection ) { string $parent = `needTheLeadTransform`; if( $parent != "" ) { int $oldVisShape = -1; int $newVisShape = -1; int $i, $n, $val, $cntr; string $shapes[] = `listRelatives -s $parent`; string $tmp; // Now, we want only one $cntr = 0; $n = size($shapes); if( $n > 1 ) { for( $i=0; $i<$n; $i+=1 ) { $val = `getAttr ($shapes[$i] + ".io")`; if( ! $val ) { $oldVisShape = $i; $cntr += 1; } } if( 1 == $cntr ) { $newVisShape = $oldVisShape + 1; if( $newVisShape >= $n ) { $newVisShape = 0; } if( ($oldVisShape >= 0) && ($newVisShape >= 0) ) { setAttr ($shapes[$oldVisShape] + ".io") true; setAttr ($shapes[$newVisShape] + ".io") false; if( $modifySelection ) { doModifySelection( $shapes[$oldVisShape], $shapes[$newVisShape] ); } } } } } }