// =========================================================================== // 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: May, 1997 // // Description: // dynExecuteFieldCommands executes the field command and // ConnectDynamic commands. // // Input Arguments(): // int $isCreate -- create or add mode // string $fieldCmd -- the field command string (except for the selection) // // Return Value: // None. // // // ============== dynExecuteFieldCommands ============== // // SYNOPSIS // Execute the field command and connectDynamic command. // If executing a "Create"/positional field command, all items in // the selection list will be connected to the field, to be // influenced by it. // If executing an "Add" field command, add the field to all // items in the selection list. // global proc dynExecuteFieldCommands(int $isCreate, string $fieldCmd) { string $selected[] = `ls -sl`; if (!$isCreate && size($selected) == 0) { warning (uiRes("m_dynExecuteFieldCommands.kNothingSelected")); return; } // filter out the names of any selected auxiliaries, // because we do not want to connect a field to another field. // The node name dynBase takes in fields, emitters, and collisions. // string $selectedAux[] = `ls -sl -type dynBase`; int $ii; for ($ii = 0; $ii < size($selected); $ii++) { // search for the name of this selected item // among the selected fields. If we find it there, // erase this item from the array. // int $jj; for ($jj = 0; $jj < size($selectedAux); $jj++) { if ($selected[$ii] == $selectedAux[$jj]) { $selected[$ii] = ""; break; } } // If this is the output mesh of an nobject, add field to // the nBase instead string $nBase = findTypeInHistory($selected[$ii],"nBase",0,1); if( size($nBase) ) { $selected[$ii] = $nBase; } } // Execute the field command. // string $fieldNames[] = evalEcho ($fieldCmd); // Currently only Drag has a currentTime attribute, which is used only // if inheritVelocity is enabled on the drag field. if( size($fieldNames) > 0 && objExists( $fieldNames[0] + ".currentTime") ){ connectAttr time1.outTime ($fieldNames[0]+".currentTime"); } // If creating a positional field, and there are objects selected, // connect them to the new field. // if ($isCreate && size($selected) > 0) { string $connectNames = ""; for ($i = 0; $i < size($selected); $i++) { string $objName = $selected[$i]; if (size($objName)>0) $connectNames = $connectNames + " " + $objName; } if (size($connectNames) > 0) { string $connectCmd = "connectDynamic -f " + $fieldNames[0] + " " + $connectNames; evalEcho($connectCmd); } } }