// =========================================================================== // 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. // =========================================================================== // // Script: nurbsToggleEditUVMode.mel // // Description: // Toggles between the use of implicit and explicit UVs on NURBS objects. // global proc nurbsToggleEditUVMode() { string $shapes[]; txtWndShapesFromSelList( $shapes ); int $nShapes = size($shapes); // Rather than toggle each NURBS object individually, we should keep the // final state consistent across all selected objects. To do so, use // queryNurbsEditUVMode() to determine current state and toggle that for // final state. // // queryNurbsEditUVMode will return true if any selected NURBS object has // useExplicitUVs enabled. // int $currentState = queryNurbsEditUVMode(); int $finalState = !$currentState; // Create a list of shapes we've already processed, so we don't toggle back // and forth over the same shape when we should only do it once. // string $processedShapes[]; int $nProcessedShapes = size($processedShapes); int $i; string $shape; for( $i = 0; $i < $nShapes; $i++ ) { $shape = $shapes[$i]; $type = `objectType $shape`; // Firewall: Only do each shape once. // int $k; int $skipObject = 0; for( $k = 0; $k < $nProcessedShapes; $k++ ) { if( $shape == $processedShapes[$k] ) { $skipObject = 1; } } if( $skipObject ) { continue; } string $cmd; if( $type == "nurbsSurface" ) { int $hasExplicitUVs[] = `nurbsUVSet -q -c $shape`; // If the object does not have a nurbs UV set on it yet, create one. // if( !$hasExplicitUVs[0] ) { catch(`nurbsUVSet -c $shape`); } // Now toggle the use explicit flag. // $hasExplicitUVs = `nurbsUVSet -q -c $shape`; if( $hasExplicitUVs[0] ) { nurbsUVSet -ue $finalState $shape; } $processedShapes[$nProcessedShapes] = $shape; $nProcessedShapes = size($processedShapes); } } }