// =========================================================================== // 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 int performPolyCopyUVsToUVsetArgList ( string $version, string $args[] ) // // $args // Version 1 // [0] $inputUVset: The uv set to copy from. // [1] $toUVset: The uv set to be copied to. // [2] $createNewSet: Whether or not to force creation of a new UV set { // First version of this proc, size of array must be 3. if( size($args) != 3) { error((uiRes("m_performPolyCopyUVsToUVsetArgList.kIncorrectParamNumber"))); return 0; } string $inputUVset = $args[0]; string $toUVset = $args[1]; int $createNewSet = $args[2]; // Check that there is a valid selection: single poly object // or selected faces from a single objct // else display warning // Returns >0 if something was done, otherwise returns 0 // Check first if there's a selected object // It must be a mesh shape or its child shape must be a mesh shape // Or it must be string $compSelType = `getComponentMask`; string $selection[] = `ls -sl`; string $selectComp[] = `filterExpand -ex false -sm 34`; // 34 means poly mesh faces string $selectObj[] = `ls -o -sl`; int $numObjects = size($selectObj); string $shapes[]; if( $numObjects > 0) { $shapes = `listRelatives -shapes -fullPath $selectObj[0]`; } if( (($numObjects > 0) && (`nodeType $selectObj[0]` == "mesh")) || ((size($shapes) > 0) && (`nodeType $shapes[0]` == "mesh" ))) { // if the object doesn't have any uvsets, then // warning that it's not allowed and return 0 string $uvsets[] = {"BootUVs" }; //`getUVs($inputUVset)`; if( size($uvsets) == 0 ) { error((uiRes("m_performPolyCopyUVsToUVsetArgList.kEmptyCurrUVSet"))); return 0; } // Get the selected components, if any string $copyCmd = ( "polyCopyUV -uvSetNameInput \"" + $inputUVset + "\" -uvSetName \"" + $toUVset + "\" "); if ($createNewSet) { $copyCmd += "-createNewMap 1"; } // If it's only one object with face components, then put no argument // If it's only one object with no face componnets, then convert the obj to its faces // If it's >1 object, then put the first selection item if( ($numObjects == 1) && (size($selectComp)==0)) { $copyCmd = ( "polyCopyUV -uvSetNameInput \\\"" + $inputUVset + "\\\" -uvSetName \\\"" + $toUVset + "\\\" "); if ($createNewSet) { $copyCmd += "-createNewMap 1"; } $copyCmd = ("polyPerformAction \"" + $copyCmd + "\" \"f\" 0;"); } else if( $numObjects > 1 ) { $copyCmd += ($selection[0] + "; "); } // if selection was > 1 object and really only // 1 object is being used, then print a warning if( $numObjects > 1 ) { string $warnString = (uiRes("m_performPolyCopyUVsToUVsetArgList.kOnlyWorkedOnFirst")); warning(`format -s $selectObj[0] $warnString`); } eval( $copyCmd ); //restore the original component mask setComponentMask($compSelType); if ($compSelType == "polymeshUV") // UVs are always renumbered by the action ConvertSelectionToUVs; else //select the original selection select -replace $selection; // Need to somehow test that the copy was successful // Return 1 to say that something was done return 1; } else { error((uiRes("m_performPolyCopyUVsToUVsetArgList.kNOObjSel"))); } // Return 0 to say that nothing was done; return 0; }