// =========================================================================== // 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. // =========================================================================== // // // // // // getSelectedNObjs( string $type ) // // // string array containing nDynamics objects of the specified type that are either directly or indirectly selected. // // // With nDynamics objects it can be useful to get selected nodes indirectly. For example if the output mesh of an nCloth node // is selected then calling this with "nCloth" will return the nCloth node, not the mesh. One can also get all the nodes of // a given type connected to a selected nucleus node. // // // string $type This is the nodetype to return, for example "nCloth", "nRigid", "nParticle", or "nucleus". // // // string $clothObjs[] = getSelectedNObjs( "nCloth" ); // global proc string[] getSelectedNObjs( string $nType ) { // First, find the nObjs directly selected // string $nObjs[] = `ls -sl -dag -type $nType`; int $badSelection = true; // Next, find the nodes of type nucleus directly selected, and add all their // nObjs to the list // string $nuclei[] = `ls -sl -dag -type nucleus`; int $arraySize = size($nuclei); int $index = 0; while( $index < $arraySize ){ string $nNode = $nuclei[$index]; string $tmp[] = `listConnections -s false -sh true -d true -type $nType $nNode`; string $cat[] = stringArrayCatenate( $nObjs, $tmp ); clear $nObjs; $nObjs = stringArrayRemoveDuplicates( $cat ); $index++; } // Next, find the nodes of type mesh directly selected, and add their // associated nObjs to the list. // string $meshes[] = `ls -sl -dag -type mesh`; $arraySize = size($meshes); $index = 0; while( $index < $arraySize ){ string $nNode = $meshes[$index]; string $tmp[] = `listConnections -s true -sh true -d true -type $nType $nNode`; if(size($tmp) == 0) { string $upstreamSel[] = `listHistory`; $tmp = `ls -type nCloth $upstreamSel`; } string $cat[] = stringArrayCatenate( $nObjs, $tmp ); clear $nObjs; $nObjs = stringArrayRemoveDuplicates( $cat ); $index++; } // Finally, find the nodes of type transform directly selected, and add their // associated nObjs to the list. string $transforms[] = `ls -sl -dag -type transform`; $arraySize = size($transforms); $index = 0; while( $index < $arraySize ){ string $nNode = $transforms[$index]; string $tmp[] = `listRelatives -type $nType $nNode`; string $cat[] = stringArrayCatenate( $nObjs, $tmp ); clear $nObjs; $nObjs = stringArrayRemoveDuplicates( $cat ); $index++; } return $nObjs; }