// =========================================================================== // 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: 2003 // // Description: // Option box for transplantHair menu. // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // Whether to set the options to default values. // // proc setOptionVars(int $forceFactorySettings) { if($forceFactorySettings || !`optionVar -exists transplantHairCopyFollicles`) { optionVar -intValue transplantHairCopyFollicles 0; } if($forceFactorySettings || !`optionVar -exists transplantHairMethod`) { optionVar -intValue transplantHairMethod 2; } } // // Procedure Name: // performTransplantHairSetup // // 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 performTransplantHairSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; checkBoxGrp -edit -value1 `optionVar -q transplantHairCopyFollicles` transplantHairCopyFollicles; radioButtonGrp -edit -sl `optionVar -query transplantHairMethod` transplantHairMethod; } // // Procedure Name: // performTransplantHairCallback // // Description: // Update the option values with the current state of the option box UI. // // 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 performTransplantHairCallback(string $parent, int $doIt) { setParent $parent; optionVar -intValue transplantHairCopyFollicles `checkBoxGrp -query -value1 transplantHairCopyFollicles`; optionVar -intValue transplantHairMethod `radioButtonGrp -query -sl transplantHairMethod`; if( $doIt ) { performTransplantHair 0; } } // // Procedure Name: // transplantHairOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc transplantHairOptions() { // Name of the command for this option box. // string $commandName = "performTransplantHair"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); string $layout = getOptionBox(); setParent $layout; setUITemplate -pushTemplate DefaultTemplate; tabLayout -tv false -scr true; string $parent = `columnLayout -adjustableColumn 1`; checkBoxGrp -ncb 1 -label1 (uiRes("m_performTransplantHair.kCopyFollicles")) -cc updateHSTPlaceMenu transplantHairCopyFollicles; string $radioButton1 = (uiRes("m_performTransplantHair.kMatchUV")); string $radioButton2 = (uiRes("m_performTransplantHair.kNearestPoint")); radioButtonGrp -numberOfRadioButtons 2 -cw3 170 110 200 -labelArray2 $radioButton1 $radioButton2 // -cc simulationTypeDimControl transplantHairMethod; string $defaultLabel = (uiRes("m_performTransplantHair.kSameHairSystem")); if( `optionVar -q transplantHairCopyFollicles` ) $defaultLabel = (uiRes("m_performTransplantHair.kDuplicateHairSystem")); optionMenuGrp -label (uiRes("m_performTransplantHair.kPlaceHairsInto")) hstPlaceMenu; menuItem -label $defaultLabel placeMenuItem0; // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performTransplantHair.kTransplantHair")) -command ($callback + " " + $parent + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; // Set the option box title. // setOptionBoxTitle (uiRes("m_performTransplantHair.kTransplantHairOptions")); setOptionBoxCommandName($commandName); setOptionBoxHelpTag( "TransplantHair" ); // Pop the UI template // setUITemplate -popTemplate; // Set the current values of the option box. // eval( $setup + " " + $parent + " " + 0 ); updateHSTPlaceMenu(); scriptJob -p hstPlaceMenu -e "SelectionChanged" ("updateHSTPlaceMenu"); // Show the option box. // showOptionBox(); } // // Procedure Name: // updateHSTPlaceMenu // // Description: // Update `hstPlace` menu depending on the selection list // // Input Arguments: // None. // // Return Value: // None. // global proc updateHSTPlaceMenu() { // Add any existing hair system to the place into menu // int $placeItems = `optionMenuGrp -q -ni hstPlaceMenu`; int $selectIndex = `optionMenuGrp -q -sl hstPlaceMenu`; string $placeMenuItemName="placeMenuItem"; string $placeItemSelected = `optionMenuGrp -q -v hstPlaceMenu`; int $i; // Get rid of any that are there for ( $i = 0; $i < $placeItems; $i++ ) { deleteUI ($placeMenuItemName+$i); } string $savedParent = `setParent -q`; string $fullName = `setParent hstPlaceMenu`; setParent -menu ($fullName + "|OptionMenu"); string $defaultLabel = uiRes("m_performTransplantHair.kSameHairSystem"); if( `checkBoxGrp -query -value1 transplantHairCopyFollicles` ) $defaultLabel = uiRes("m_performTransplantHair.kDuplicateHairSystem"); menuItem -label $defaultLabel placeMenuItem0; // Add all existing hair system $hairSystems = `ls -dag -ni -type hairSystem`; if ( size( $hairSystems ) > 0 ) { $selectIndex = 1; $i = 1; for ( $hs in $hairSystems ) { string $hsTforms[] =`listTransforms $hs`; $hs = $hsTforms[0]; if ( $hs == $placeItemSelected ) { $selectIndex = $i + 1; } menuItem -l $hs ($placeMenuItemName+$i); $i++; } setParent $savedParent; // The following if-else is a workaround for a refresh problem // that occurred with the option menu // if ( $selectIndex > 1 ) { optionMenuGrp -e -sl ($selectIndex - 1) hstPlaceMenu; } else { optionMenuGrp -e -sl ($selectIndex + 1) hstPlaceMenu; } optionMenuGrp -e -sl $selectIndex hstPlaceMenu; } setParent $savedParent; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // None. // proc string assembleCmd() { setOptionVars(false); string $cmd = ("doTransplantHair " + `optionVar -query transplantHairMethod` + " " + `optionVar -query transplantHairCopyFollicles` ); return $cmd; } // // Procedure Name: // performTransplantHair // // Description: // Perform the command using the corresponding // option values. This procedure will also show the option box // window if necessary as well as construct the command string // that will invoke the command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // // Return Value: // None. // global proc string performTransplantHair(int $action) { string $cmd = ""; switch ($action) { // Execute the command from option settings. // case 0: setOptionVars(false); $cmd = `assembleCmd`; eval($cmd); break; // Show the option box. // case 1: transplantHairOptions(); break; // Return the command string. // case 2: setOptionVars (false); $cmd = `assembleCmd`; break; } return $cmd; }