// =========================================================================== // 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: 15/03/2017 // // Description: // Performs stack similar UV shells // // // Procedure Name: // stackSimilarShellsOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc stackSimilarShellsOptions () { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; string $commandName = "StackSimilarShells"; string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); string $layout = getOptionBox(); setParent $layout; setUITemplate -pushTemplate OptionBoxTemplate; waitCursor -state 1; // Form layout string $parent = `formLayout stackSimilarShellsOptions`; // Settings frame string $settingsFrame = `frameLayout -label (uiRes("m_performStackSimilarShells.kSettingsFrame"))`; columnLayout; floatSliderGrp -label (uiRes("m_performStackSimilarShells.kTolerance")) -min 0.0 -max 1.0 -v 0.05 stackSimilarTolerance; checkBoxGrp -label (uiRes("m_performStackSimilarShells.kSelectStackedShells")) -numberOfCheckBoxes 1 selectStackedShells; setParent ..; // columnLayout setParent $parent; // frameLayout setParent ..; // formLayout // Attach Settings frame to form layout formLayout -e -af $settingsFrame "top" $gOptionBoxTemplateFrameSpacing -af $settingsFrame "left" $gOptionBoxTemplateFrameSpacing -af $settingsFrame "right" $gOptionBoxTemplateFrameSpacing -an $settingsFrame "bottom" $parent; waitCursor -state 0; setUITemplate -popTemplate; string $applyBtn = getOptionBoxApplyBtn(); button -e -command ($callback + " " + $parent + " 1;") $applyBtn; string $saveBtn = getOptionBoxSaveBtn(); button -e -command($callback + " " + $parent + " 0; hideOptionBox;") $saveBtn; string $resetBtn = getOptionBoxResetBtn(); button -e -command($setup + " " + $parent + " 1") $resetBtn; setOptionBoxTitle((uiRes("m_performStackSimilarShells.kStackSimilarShellsOptions"))); setOptionBoxHelpTag($commandName); eval (($setup + " " + $parent + " " + 0)); showOptionBox(); } // // Procedure Name: // stackSimilarShellsCallback // // Description: // Update the option values and execute command // // Input Arguments: // parent - Top level parent layout of the option box UI. Required so // that UI object names can be successfully resolved. // // doIt - Whether the command should execute. // // Return Value: // None. // global proc StackSimilarShellsCallback(string $parent, int $doIt) { stackSimilarShellsSetOptionVars (false); setParent $parent; float $tolerance = `floatSliderGrp -q -value stackSimilarTolerance`; if(`floatSliderGrp -q -ex stackSimilarTolerance`) optionVar -floatValue stackSimilarToleranceOptVar $tolerance; int $selectStacked = `checkBoxGrp -q -value1 selectStackedShells`; if(`checkBoxGrp -q -ex selectStackedShells`) optionVar -intValue selectStackedShellsOptVar $selectStacked; if($doIt) performStackSimilarShells 0; } // // Procedure Name: // stackSimilarShellsSetup // // Description: // Update the state of the option box UI to reflect the option values. // // Input Arguments: // parent - Top level parent layout of the option box UI. // Required so that UI object names can be // successfully resolved. // // forceFactorySettings - Whether the option values should be set to // default values. // // Return Value: // None. // global proc StackSimilarShellsSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // stackSimilarShellsSetOptionVars ($forceFactorySettings); setParent $parent; float $tolerance = `optionVar -q stackSimilarToleranceOptVar`; if(`floatSliderGrp -q -ex stackSimilarTolerance`) floatSliderGrp -e -value $tolerance stackSimilarTolerance; int $selectStacked = `optionVar -q selectStackedShellsOptVar`; if(`checkBoxGrp -q -ex selectStackedShells`) checkBoxGrp -e -value1 $selectStacked selectStackedShells; } // // Procedure Name: // stackSimilarShellsSetOptionVars // // Description: // Initialize the option values. // // Input Arguments: // forceFactorySettings - Whether to set the options to default values. // // Return Value: // None. // global proc stackSimilarShellsSetOptionVars(int $forceFactorySettings) { if ($forceFactorySettings || !`optionVar -ex stackSimilarToleranceOptVar`) optionVar -floatValue stackSimilarToleranceOptVar 0.1; if ($forceFactorySettings || !`optionVar -ex selectStackedShellsOptVar`) optionVar -intValue selectStackedShellsOptVar 0; } proc string assembleCmd(string $selection[]) { stackSimilarShellsSetOptionVars(false); string $cmd = "polyUVStackSimilarShells -to "; float $tolerance = `optionVar -q stackSimilarToleranceOptVar`; $cmd += $tolerance; for($i = 0; $i < size($selection); $i++) { $cmd = $cmd + " \"" + $selection[$i] + "\""; } return $cmd; } proc selectStackedUVShell(string $stackedUVs) { eval("select -r " + $stackedUVs); string $mask = getComponentMask(); int $faceSelecting = ($mask == "facet"); int $edgeSelecting = ($mask == "edge"); int $vertexSelecting = ($mask == "vertex"); int $uvShellSelecting = ($mask == "meshUVShell"); if(!$faceSelecting && !$edgeSelecting && !$vertexSelecting && !$uvShellSelecting) return; if($faceSelecting || $uvShellSelecting) ConvertSelectionToFaces; else if ($edgeSelecting) { ConvertSelectionToVertices; ConvertSelectionToContainedEdges; } else if($vertexSelecting) ConvertSelectionToVertices; } proc string[] getSelection() { string $selection[] = `ls -selection`; string $compSelType = `getComponentMask`; if($compSelType == "none") { $selection = `ls -dag -selection`; for($i = 0; $i < size($selection); $i++) { if(`nodeType $selection[$i]` == "mesh") $selection[$i] = $selection[$i] + ".f[*]"; } } return $selection; } proc stackSimilarShells() { string $selection[] = getSelection(); $cmd = assembleCmd($selection); string $stackedUVsArray[] = evalEcho($cmd); int $selectStacked = `optionVar -q selectStackedShellsOptVar`; if ($selectStacked) { string $stackedUVs = stringArrayToString($stackedUVsArray, " "); selectStackedUVShell($stackedUVs); } } // // Procedure Name: // performStackSimilarShells // // Description: // Prepare parameters and run texstackSimilarShells // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performStackSimilarShells(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: stackSimilarShells(); break; // Show the option box. // case 1: stackSimilarShellsOptions(); break; // Return the command string. // case 2: // Get the command. // string $selection[] = getSelection(); $cmd = assembleCmd($selection); break; } return $cmd; }