// =========================================================================== // 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. // =========================================================================== // // Procedure Name: // rearrangeSelection // // Description: // This procedure generate per-object selection list array. // Input Arguments: // $totalSelected : Selection list. Typically from command ls -sl. // Return Value: // An string array. Each element has and only has one object. // // Usage Example: // Let modeling command perform operation on multiple objects if the command can only perform operation on single object. // // string $objects[] = `ls -sl`; // string $resultantSelection[] = rearrangeSelection($objects); // if (size($resultantSelection) > 1) // { // int $i; // for($i = 0; $i < size($resultantSelection);$i++) // { // polyFlipUV -flipType 0 -local on $resultantSelection[$i]; // } // } // global proc string[] rearrangeSelection(string $totalSelected[]) { string $beforeDot[]; string $resultantSelection[]; for( $i = 0; $i < size($totalSelected); $i++ ) { string $buffer[]; tokenize($totalSelected[$i], ".", $buffer); // Try to get shape object from $totalSelected[$i]. Use shape-class object to remove duplicated objects and non-shape object. // For example, if $totalSelected contains polySphere1, pSphere1, pSphereShape1, and pSphere1.f[30], // Use `ls -s $totalSelected[$i]` to get pSphereShape1. // Use `listRelatives -s -c $totalSelected[$i]` to get pSphereShape1 from pSphere1. // Use `listRelatives -s -p $totalSelected[$i]` to get pSphereShape1 from pSphere1.f[30]. // If $totalSelected[$i] is polySphere1, then all the three commands will not return and shape object. string $shapes[] = `ls -s $totalSelected[$i]`; // This is to deal with pSphereShape1. if (size($shapes) == 0) $shapes = `listRelatives -s -c $totalSelected[$i]`; // This is to deal with case pSphere1. if (size($shapes) == 0) $shapes = `listRelatives -s -p $totalSelected[$i]`; // This is to deal with case pSphere1.f[30]. if (size($shapes) == 0) continue; // This is a non-dag object e.g. case polySphere1. // For those selected object with a "*", need to add "" to them. So one elment in the result might be ""pSphereShape1.f[*]"". // Maya-39990. If not add "", calling `polyFlipUV -flipType 0 -local on pSphereShape1.f[*]` failed with error. int $fullComponent = 0, $length = size($buffer[1])-1; if ($length >= 3 && `substring $buffer[1] $length $length` == "*") $fullComponent = 1; // Use $shapes[0] to build $beforeDot. $buffer[0] = $shapes[0]; int $index = -1; for( $j = 0; $j < size($beforeDot); $j++ ) { if($beforeDot[$j] == $buffer[0]) { $index = $j; break; } } if($index == -1) { $beforeDot[size($beforeDot)] = $buffer[0]; if ($fullComponent) $resultantSelection[size($resultantSelection)] = "\""+$totalSelected[$i]+"\""; else $resultantSelection[size($resultantSelection)] = $totalSelected[$i]; } else { if ($fullComponent) $resultantSelection[$index] = $resultantSelection[$index] + " " + "\"" + ($totalSelected[$i]) + "\""; else $resultantSelection[$index] = $resultantSelection[$index] + " " + ($totalSelected[$i]); } } return $resultantSelection; }