// =========================================================================== // 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: Mar. 14, 1997 // // Description: // The closePreset() procedure executes a close operation on each // selected object based on the close option vars. // // Input Arguments: // None. // // Return Value: // None. // global proc closePreset(int $doHistory, int $preserveShape, int $replaceOriginal, int $closeSurfaceDirection) { // Get a list of each type of acceptable object type - surfaces, // curves, and curves-on-surface. // global int $gSelectNurbsSurfacesBit; global int $gSelectNurbsCurvesBit; global int $gSelectCurvesOnSurfacesBit; global int $gSelectIsoparmsBit; string $surfaceList[] =`filterExpand -ex true -sm $gSelectNurbsSurfacesBit`; string $isoList[] = `filterExpand -ex true -sm $gSelectIsoparmsBit`; string $curveList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit`; string $COSList[] = `filterExpand -ex true -sm $gSelectCurvesOnSurfacesBit`; // Set up command strings for each command and execute them: // closeSurface and closeCurve and closeCurve for curves-on-surface. // string $cmd; $cmd = "closeSurface -d " + $closeSurfaceDirection + " -ps " + $preserveShape + " -ch " + $doHistory + " -rpo " + $replaceOriginal + " %s;"; string $surfaceResults[] = executeForEachObject( $surfaceList, $cmd ); $cmd = "closeCurve" + " -ch " + $doHistory + " -ps " + $preserveShape + " -rpo " + $replaceOriginal + " %s;"; string $curveResults[] = executeForEachObject( $curveList, $cmd ); $cmd = "closeCurve " + " -ch " + $doHistory + " -ps " + $preserveShape + " -rpo " + $replaceOriginal + " -cos on %s;"; string $cosResults[] = executeForEachObject( $COSList, $cmd ); // Processing isoparms is a little more involved. Use groupObjectsByName(). // This big loop groups and processes >1 isoparms and sets the // direction of the command based on the isoparm direction. // Also, if the user selects an isoparm in each direction on the same // surface, this code assumes that the user wants to close the // surface in BOTH directions. // $cmd = "closeSurface " + " -ps " + $preserveShape + " -ch " + $doHistory + " -rpo " + $replaceOriginal + " "; string $isoparmResults[]; string $isoparms[] = groupObjectsByName( $isoList, "\\." ); int $numIsoStrs = size($isoparms); for( $i = 0; $i < $numIsoStrs; $i ++ ) { string $closeCmd; string $results[]; string $objectName[]; $numNames = `tokenize $isoparms[$i] " " $objectName`; if( $numNames == 1 ) { $closeCmd = $cmd + " " + $isoparms[$i]; } else { string $foundU = `match "\\.u\\[" $isoparms[$i]`; string $foundV = `match "\\.v\\[" $isoparms[$i]`; if( size($foundU) > 0 && size($foundV) > 0 ) { tokenize $isoparms[$i] "\\." $objectName; $closeCmd = $cmd + "-d 2 " + $objectName[0]; } else { tokenize $isoparms[$i] " " $objectName; $closeCmd = $cmd + " " + $objectName[$i]; } } if( catch( $results = evalEcho( $closeCmd )) ) { error( `format -s $closeCmd (uiRes("m_closePreset.kErrorProblemExecuting"))` ); } else { int $j; int $numResults = size( $results ); int $numIsoResults = size( $isoparmResults ); for( $j = 0; $j < $numResults; $j ++, $numIsoResults ++ ) { $isoparmResults[$numIsoResults] = $results[$j]; } } } // Process all the results - if there weren't any then display a error // if( (size($surfaceResults) + size($isoparmResults) + size($curveResults) + size($cosResults) ) == 0 ) { error ((uiRes("m_closePreset.kErrorNothingSelected")) ); } else { // Select all the results with one select command. Note that only // resulting surfaces and curves are selected, not dependency nodes. // string $selectString; $selectString = "select "; int $i; int $numSurfaces = size($surfaceResults); for( $i = 0; $i < $numSurfaces; $i ++ ) { $selectString += $surfaceResults[$i]; $selectString += " "; } int $numIsos = size($isoparmResults); for( $i = 0; $i < $numIsos; $i ++ ) { $selectString += $isoparmResults[$i]; $selectString += " "; } int $numCurves = size($curveResults); for( $i = 0; $i < $numCurves; $i ++ ) { $selectString += $curveResults[$i]; $selectString += " "; } int $numCOS = size($cosResults); for( $i = 0; $i < $numCOS; $i ++ ) { $selectString += $cosResults[$i]; $selectString += " "; } $selectString += ";"; select -cl; eval($selectString); } }