// =========================================================================== // 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. // =========================================================================== // // Description: // Returns all selected param locators on curves. A list of selected locator // shape names are returned. Any selected items with components are ignored. // // global proc string[] findSelectedCurveLocators() { // Go through the selection list and check the type of each // selected shape. If the shape is a locator, and is in the // underworld of a curve, then it's a curve locator. // string $locatorNames[]; string $selectionList[] = `ls -sl`; int $numSelected = size($selectionList); int $i, $j; for( $i = 0; $i < $numSelected; $i ++ ) { // Reject all selection items with components // string $s = match( "\\.", $selectionList[$i]); if( size($s) > 0 ) { continue; } // Reject all selection items that DO NOT have "->" (which indicates // an object in the underworld) // string $s2 = match( "->", $selectionList[$i]); if( size($s2) == 0 ) { continue; } // Get all the shapes under this selection item // string $shapes[] = `listRelatives -s $selectionList[$i]`; int $numShapes = size($shapes); // If the shape was the selection item, then "listRelatives" returns // nothing. So add the case here so it will be processed. // if( $numShapes == 0 ) { $shapes[0] = $selectionList[$i]; $numShapes = 1; } // For each shape // for( $j = 0; $j < $numShapes; $j ++ ) { // Check if the shape is a locator // if( `nodeType $shapes[$j]` == "locator" ) { // Get the parent of the selection item // string $parent[] = `listRelatives -ap $selectionList[$i]`; // If the parent of the selection item is a transform, // then go up another level to its parent. eg. if the // selection item was the locator shape, then its 1st parent // is the locator transform, and the parent above is the // nurbs curve. // if( `nodeType $parent[0]` == "transform") { $parent = `listRelatives -ap $parent[0]`; } // If the parent is a nurbs Curve, then store the path to // the locator shape. // if( `nodeType $parent[0]` == "nurbsCurve" ) { string $tmp[] = `listRelatives -pa $shapes[$j]`; if( size($tmp) == 0 ) { $locatorNames[ size($locatorNames) ] = $shapes[$j]; } else { $locatorNames[ size($locatorNames) ] = $tmp[0]; } } } } } return $locatorNames; }