// =========================================================================== // 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. // =========================================================================== global proc buildCopyUVsToUVSetMenu( string $parentMenu, string $prefix, int $hasStaticItems, string $inputObj ) { if(!`menu -q -exists $parentMenu`) return; if(!$hasStaticItems) { // Menu does not have static items, so remove all the items menu -e -deleteAllItems $parentMenu; } else { // Remove all the menu items except the last one. // NOTE: The last item could have the option box. In this case we have to preserve 2 items. string $items[] = `menu -q -itemArray $parentMenu`; int $itemCount = size($items); int $i; if($itemCount > 0) { int $isOptionBox = `menuItem -q -isOptionBox $items[$itemCount-1]`; int $itemsToPreserve = $isOptionBox ? 3 : 2; for ($i=0; $i<$itemCount-$itemsToPreserve; $i++) { deleteUI -menuItem $items[$i]; } } } setParent -m $parentMenu; string $copySelectedAnnot = (uiRes("m_buildCopyUVsToUVSetMenu.kCopySelectedFaceAnnot")); string $selectObj[] = `ls -dag -ni -o -g -sl`; string $hiliteList[] = `ls -dag -ni -o -g -hl`; $selectObj = stringArrayCatenate( $selectObj, $hiliteList ); $selectObj = stringArrayRemoveDuplicates( $selectObj ); if ($inputObj != "") { $selectObj = {$inputObj}; } int $numObjects = size($selectObj); // only add a maximum number of 100 menu items. Anything more is unreasonable. int $maxObjects = 100; // If there are no UV sets to display, then put an empty menu item if( $numObjects == 0 ) { menuItem -enableCommandRepeat false -enable false -label (uiRes("m_buildCopyUVsToUVSetMenu.kUVSetNoObjectSelected")) -insertAfter "" ( $prefix + "CopyUVsToUVSetNoObject" ); setParent -menu ..; return; } else if($numObjects > $maxObjects) { $numObjects = $maxObjects; } for ($i = $numObjects - 1; $i >= 0; $i--) { $allSets = `polyUVSet -pi 1 -query -allUVSets $selectObj[$i]`; string $uvSetsPerObject[]; for( $set in $allSets ) { string $perInstUVSet[] = `polyUVSet -uvSet $set -q -pi $selectObj[$i]`; if (size($perInstUVSet[0]) > 0) { $uvSetsPerObject[size($uvSetsPerObject)] = $perInstUVSet[0]; } else { continue; } } int $numUVSets = size($uvSetsPerObject); string $currUVSet[] = `polyUVSet -pi 1 -query -currentUVSet $selectObj[$i]`; // when multiple objects are selected, group UV sets together by object. int $uvSetIndices[]; if($numObjects > 1) { menuItem -label $selectObj[$i] -subMenu 1 -insertAfter "" ( $prefix + "CopyUVsToUVSetObject" + $i ); for ($j = 0; $j < $numUVSets; $j++) { $uvSetIndices[size($uvSetIndices)] = $j; } } else { for ($j = $numUVSets - 1; $j >= 0; $j--) { $uvSetIndices[size($uvSetIndices)] = $j; } } for ($j = 0; $j < size($uvSetIndices); $j++) { int $index = $uvSetIndices[$j]; string $uvSet = $uvSetsPerObject[$index]; int $isCurrent = ($currUVSet[0] == $uvSet); // if it is a per-instance set, display the set related to the select object string $perInstanceUVSet[] = `polyUVSet -uvSet $uvSet -q -pi $selectObj[$i]`; if(size($perInstanceUVSet) > 0) { $uvSet = $perInstanceUVSet[0]; } string $setCurrentUVSetCmd = ("polyUVSet -currentUVSet -uvSet \"" + $uvSet + "\" " + $selectObj[$i] + ";"); string $copyCmd = ( "if( `performPolyCopyUVsToUVsetArgList \"1\" {\"" + $currUVSet[0] + "\", \"" + $uvSet + "\", \"0\"}` > 0 ) { " + $setCurrentUVSetCmd + "}" ); if($numObjects > 1) { menuItem -enableCommandRepeat false -label $uvSet -command $copyCmd -enable (!$isCurrent) -annotation $copySelectedAnnot ( $prefix + "CopyUVsToUVSetObjectUVSet" + $index ); } else { menuItem -enableCommandRepeat false -label $uvSet -command $copyCmd -enable (!$isCurrent) -annotation $copySelectedAnnot -insertAfter "" ( $prefix + "CopyUVsToUVSetObjectUVSet" + $index ); } } if($numUVSets > 0) setParent -menu ..; } if ($numObjects > 1) setParent -menu ..; if (size($selectObj) > $maxObjects) { //if we were not able to add all items add one more menu item to //indicate this to the user. menuItem -enableCommandRepeat false -enable false -label (uiRes("m_buildCopyUVsToUVSetMenu.kUVSetTooManySelected")) -insertAfter "" ( $prefix + "CopyUVsToUVSetTooManyObjects" ); } }