// =========================================================================== // 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: // Move selected components to their nearest neighbors // // // 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 matchUVTolerance`) optionVar -fv matchUVTolerance 0.01; } proc polyMatchUVsOptions() { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; // Name of the command for this option box. // string $commandName; $commandName = "MatchUVs"; // 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 polyMatchUVsOptions`; // Settings frame string $settingsFrame = `frameLayout -label (uiRes("m_performPolyMatchUVs.kSettingsFrame"))`; columnLayout -adjustableColumn true; // Tolerance floatFieldGrp -label (uiRes("m_performPolyMatchUVs.kTolerance")) polyMatchUVsToleranceField; 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_performPolyMatchUVs.kMatchUVsOptions"))); // 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: // MatchUVsCallback // // 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 MatchUVsCallback(string $parent, int $doIt) { setOptionVars(false); setParent $parent; if(`floatFieldGrp -q -ex polyMatchUVsToleranceField`) optionVar -fv matchUVTolerance (`floatFieldGrp -q -value1 polyMatchUVsToleranceField`); if($doIt) performPolyMatchUVs 0; } // // Procedure Name: // MatchUVsSetup // // 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 MatchUVsSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; if(`floatFieldGrp -q -ex polyMatchUVsToleranceField`) { float $tolerance = `optionVar -q matchUVTolerance`; floatFieldGrp -e -value1 $tolerance polyMatchUVsToleranceField; } } proc string assembleCmd() { setOptionVars(false); string $cmd = "texMatchUVs "; float $tolerance = `optionVar -q matchUVTolerance`; $cmd += $tolerance; return $cmd; } // // Procedure Name: // performPolyDistributeUVs // // Description: // Prepare parameters and run texMatchUVs // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performPolyMatchUVs(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: $cmd = assembleCmd(); // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: polyMatchUVsOptions(); break; // Return the command string. // case 2: // Get the command. // $cmd = assembleCmd(); break; } return $cmd; }