// =========================================================================== // 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: 18 December 2016 // // Description: // Distribute UV shells towards a direction or target shell // // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // forceFactorySettings - Whether to set the options to default values. // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { if($forceFactorySettings || !`optionVar -ex distributeShellsDirection`) optionVar -iv distributeShellsDirection 1; if($forceFactorySettings || !`optionVar -ex distributeShellsPadding`) optionVar -fv distributeShellsPadding 0.0000; } global proc updateShellPadding() { if(`floatFieldGrp -q -ex polyDistributeShellsPaddingField`) { int $selectedItem = `optionMenuGrp -query -select polyDistributeShellsDirectionGrp`; floatFieldGrp -e -enable ($selectedItem != 5) polyDistributeShellsPaddingField; } } proc polyDistributeShellsOptions() { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; // Name of the command for this option box. // string $commandName; $commandName = "DistributeShells"; // Build the option box actions. // string $callback = $commandName + "Callback"; string $setup = $commandName + "Setup"; // STEP 1: Get the option box. // ============================ // // The value returned is the name of the layout to be used as // the parent for the option box UI. // string $layout = getOptionBox(); // STEP 2: Pass the command name to the option box. // ================================================= // // Any default option box behaviour based on the command name is set // up with this call. For example, updating the 'Help' menu item with // the name of the command. // setOptionBoxCommandName($commandName); // STEP 3: Create option box contents. // ==================================== // setParent $layout; setUITemplate -pushTemplate OptionBoxTemplate; waitCursor -state 1; // Form layout string $parent = `formLayout polyDistributeShellsOptions`; // Settings frame string $settingsFrame = `frameLayout -label (uiRes("m_performPolyDistributeShells.kSettingsFrame"))`; columnLayout -adjustableColumn true; optionMenuGrp -label (uiRes("m_performPolyDistributeShells.kDistributeShellsDirection")) -changeCommand "updateShellPadding" polyDistributeShellsDirectionGrp; menuItem -label (uiRes("m_performPolyDistributeShells.kRight")); menuItem -label (uiRes("m_performPolyDistributeShells.kLeft")); menuItem -label (uiRes("m_performPolyDistributeShells.kUp")); menuItem -label (uiRes("m_performPolyDistributeShells.kDown")); menuItem -label (uiRes("m_performPolyDistributeShells.kTowardsTarget")); // Distance floatFieldGrp -label (uiRes("m_performPolyDistributeShells.kDistributionDistance")) polyDistributeShellsPaddingField; 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; // STEP 4: Customize the buttons. // =============================== // // Provide more descriptive labels for the buttons. // Disable those buttons that are not applicable to the option box. // Attach actions to those buttons that are applicable to the option box. string $applyAndCloseBtn = getOptionBoxApplyAndCloseBtn(); button -e -command ($callback + " " + $parent + " 1; hideOptionBox;") $applyAndCloseBtn; string $applyBtn = getOptionBoxApplyBtn(); button -e -command ($callback + " " + $parent + " 1;") $applyBtn; string $resetBtn = getOptionBoxResetBtn(); button -e -command($setup + " " + $parent + " 1") $resetBtn; string $saveBtn = getOptionBoxSaveBtn(); button -e -command($callback + " " + $parent + " 0; hideOptionBox;") $saveBtn; // STEP 5: Set the option box title. // ================================== // setOptionBoxTitle((uiRes("m_performPolyDistributeShells.kDistributeShellsOptions"))); // STEP 6: Customize the 'Help' menu item text. // ============================================= // setOptionBoxHelpTag($commandName); // Set the current values of the option box. // ========================================= // eval ($setup + " " + $parent + " 0"); // Show the option box. // ==================== // showOptionBox(); } // // Procedure Name: // DistributeShellsCallback // // 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 DistributeShellsCallback(string $parent, int $doIt) { setOptionVars(false); setParent $parent; if(`optionMenuGrp -q -ex polyDistributeShellsDirectionGrp`) optionVar -iv distributeShellsDirection (`optionMenuGrp -q -select polyDistributeShellsDirectionGrp`); if(`floatFieldGrp -q -ex polyDistributeShellsPaddingField`) optionVar -fv distributeShellsPadding (`floatFieldGrp -q -value1 polyDistributeShellsPaddingField`); if($doIt) performPolyDistributeShells 0; } // // Procedure Name: // DistributeShellsSetup // // 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 DistributeShellsSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; if(`optionMenuGrp -q -ex polyDistributeShellsDirectionGrp`) { int $direction = `optionVar -q distributeShellsDirection`; optionMenuGrp -e -select $direction polyDistributeShellsDirectionGrp; } if(`floatFieldGrp -q -ex polyDistributeShellsPaddingField`) { float $padding = `optionVar -q distributeShellsPadding`; floatFieldGrp -e -value1 $padding polyDistributeShellsPaddingField; } updateShellPadding(); } proc string assembleCmd() { setOptionVars(false); string $cmd = "texDistributeShells "; int $dir = `optionVar -q distributeShellsDirection`; if( $dir == 5 ) { $cmd += 1; $cmd += " "; $cmd += 0.0; $cmd += " \"\" {}"; } else { $cmd += 0; $cmd += " "; float $padding = `optionVar -q distributeShellsPadding`; $cmd += $padding; if($dir == 1) $cmd += " right "; else if($dir == 2) $cmd += " left "; else if($dir == 3) $cmd += " up "; else if($dir == 4) $cmd += " down "; $cmd += "{}"; } return $cmd; } // // Procedure Name: // performPolyDistributeShells // // Description: // Prepare parameters and run texDistributeShells // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performPolyDistributeShells(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: $cmd = assembleCmd(); // Execute the command with the option settings. // eval($cmd); break; // Show the option box. // case 1: polyDistributeShellsOptions(); break; // Return the command string. // case 2: // Get the command. // $cmd = assembleCmd(); break; } return $cmd; }