// =========================================================================== // 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. // =========================================================================== // // Description: // An option window used to transfer values and connections // from one node to another. // // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // Whether to set the options to default values. // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // copy values, default = copy // if ($forceFactorySettings || !`optionVar -exists copyAttrValues`) { optionVar -intValue copyAttrValues 1; } // copy incoming connections, default = ignore // if ($forceFactorySettings || !`optionVar -exists copyAttrInConns`) { optionVar -intValue copyAttrInConns 3; } // copy outgoing connections, default = ignore // if ($forceFactorySettings || !`optionVar -exists copyAttrOutConns`) { optionVar -intValue copyAttrOutConns 0; } // use channel box selection, default = no // if ($forceFactorySettings || !`optionVar -exists copyAttrFromCB`) { optionVar -intValue copyAttrFromCB 0; } // rename target container, default off // if ($forceFactorySettings || !`optionVar -exists copyContainerRename`) { optionVar -intValue copyContainerRename 0; } // copy container parent child relationship // if ($forceFactorySettings || !`optionVar -exists copyContainerParent`) { optionVar -intValue copyContainerParent 0; } } // // Procedure Name: // transferValuesSetup // // 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 transferValuesSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars( $forceFactorySettings ); setParent $parent; int $copyVals = `optionVar -query copyAttrValues`; checkBoxGrp -edit -value1 $copyVals copyValWidget; int $copyInputs = `optionVar -query copyAttrInConns`; switch ($copyInputs) { case 1: { checkBoxGrp -edit -value1 1 copyInConnWidget; radioButtonGrp -edit -sl 1 shareWithSource; break; } case 2: { checkBoxGrp -edit -value1 1 copyInConnWidget; radioButtonGrp -edit -sl 1 disconnectFromSource; break; } case 3: { checkBoxGrp -edit -value1 0 copyInConnWidget; radioButtonGrp -edit -sl 1 shareWithSource; // default break; } } toggleCopyAttrInConnRadio ($copyInputs != 3); int $copyOutputs = `optionVar -query copyAttrOutConns`; checkBoxGrp -edit -value1 $copyOutputs copyOutputWidget; int $fromCB = `optionVar -query copyAttrFromCB`; checkBoxGrp -edit -value1 $fromCB whichAttrWidget; int $copyParent = `optionVar -query copyContainerParent`; checkBoxGrp -edit -value1 $copyParent copyParentWidget; int $rename = `optionVar -query copyContainerRename`; checkBoxGrp -edit -value1 $rename copyAttrRenameWidget; } // // Procedure Name: // transferValuesCallback // // 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 transferValuesCallback(string $parent, int $doIt) { setParent $parent; optionVar -intValue copyAttrValues `checkBoxGrp -q -value1 copyValWidget`; optionVar -intValue copyAttrOutConns `checkBoxGrp -q -value1 copyOutputWidget`; optionVar -intValue copyAttrFromCB `checkBoxGrp -q -value1 whichAttrWidget`; optionVar -intValue copyContainerRename `checkBoxGrp -q -value1 copyAttrRenameWidget`; optionVar -intValue copyContainerParent `checkBoxGrp -q -value1 copyParentWidget`; int $copyInConns = `checkBoxGrp -q -value1 copyInConnWidget`; int $copyInputs = 3; if ($copyInConns) { if (`radioButtonGrp -q -sl shareWithSource`) { $copyInputs = 1; } else if (`radioButtonGrp -q -sl disconnectFromSource`) { $copyInputs = 2; } } optionVar -intValue copyAttrInConns $copyInputs; if ($doIt) { performTransferContainer 0; addToRecentCommandQueue "performTransferContainer 0" "Transfer Attribute Values"; } } global proc toggleCopyAttrInConnRadio(int $state) { radioButtonGrp -e -enable $state shareWithSource; radioButtonGrp -e -enable $state disconnectFromSource; } // // Procedure Name: // transferValuesOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc transferValuesOptions() { global int $gOptionBoxTemplateDescriptionMarginWidth; global int $gOptionBoxTemplateFrameSpacing; // Name of the command for this option box. // string $commandName = "transferValues"; // 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(); setParent $layout; // 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("copyAttr"); // STEP 3: Activate the default UI template. // ========================================== // // Activate the default UI template so that the layout of this // option box is consistent with the layout of the rest of the // application. // setUITemplate -pushTemplate OptionBoxTemplate; // STEP 4: Transfer option box contents. // =================================== // // This, of course, will vary from option box to option box. // Turn on the wait cursor. // waitCursor -state 1; string $parent = `formLayout`; string $generalFrame = `frameLayout -collapsable 0 -label (uiRes("m_performTransferContainer.kGeneralOptions")) -mw $gOptionBoxTemplateDescriptionMarginWidth`; columnLayout; checkBoxGrp -ncb 1 -label (uiRes("m_performTransferContainer.kAttributes")) -label1 (uiRes("m_performTransferContainer.kFromChannelBox")) -annotation (uiRes("m_performTransferContainer.kAttributesAnnot")) whichAttrWidget; checkBoxGrp -ncb 1 -label (uiRes("m_performTransferContainer.kValues")) copyValWidget; checkBoxGrp -ncb 1 -label (uiRes("m_performTransferContainer.kInConnections")) -onc "toggleCopyAttrInConnRadio 1" -ofc "toggleCopyAttrInConnRadio 0" copyInConnWidget; radioButtonGrp -label "" -label1 (uiRes("m_performTransferContainer.kShareWithSource")) -annotation (uiRes("m_performTransferContainer.kShareWithSourceAnnot")) shareWithSource; radioButtonGrp -label "" -label1 (uiRes("m_performTransferContainer.kDisconnectFromSource")) -annotation (uiRes("m_performTransferContainer.kDisconnectFromSourceAnnot")) -scl shareWithSource disconnectFromSource; checkBoxGrp -ncb 1 -label (uiRes("m_performTransferContainer.kOutConnections")) -annotation (uiRes("m_performTransferContainer.kOutConnectionsAnnot")) copyOutputWidget; setParent $parent; string $containerFrame = `frameLayout -collapsable 0 -label (uiRes("m_performTransferContainer.kAssetOptions")) -mw $gOptionBoxTemplateDescriptionMarginWidth`; columnLayout; checkBoxGrp -ncb 1 -label (uiRes("m_performTransferContainer.kRelationships")) -label1 (uiRes("m_performTransferContainer.kTransformParent")) copyParentWidget; checkBoxGrp -ncb 1 -label (uiRes("m_performTransferContainer.kRename")) -label1 (uiRes("m_performTransferContainer.kRenameTargetAsset")) copyAttrRenameWidget; setParent $parent; setParent ..; formLayout -e -af $generalFrame "top" $gOptionBoxTemplateFrameSpacing -af $generalFrame "left" $gOptionBoxTemplateFrameSpacing -af $generalFrame "right" $gOptionBoxTemplateFrameSpacing -an $generalFrame "bottom" -ac $containerFrame "top" $gOptionBoxTemplateFrameSpacing $generalFrame -af $containerFrame "left" $gOptionBoxTemplateFrameSpacing -af $containerFrame "right" $gOptionBoxTemplateFrameSpacing -an $containerFrame "bottom" $parent; // Turn off the wait cursor. // waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // // Provide more descriptive labels for the buttons. This is not // necessary, but in some cases, for example, a button labelled // 'Transfer' may be more meaningful to the user than one labelled // 'Apply'. // // Disable those buttons that are not applicable to the option box. // // Attach actions to those buttons that are applicable to the option // box. Note that the 'Close' button has a default action attached // to it that will hide the window. If a a custom action is // attached to the 'Close' button then be sure to call the 'hide the // option box' procedure within the custom action so that the option // box is hidden properly. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -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; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performTransferContainer.kTransferAttrValuesOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "TransferAttributeValues" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd = "copyAttr "; setOptionVars(false); if (`optionVar -q copyAttrValues`) { $cmd += "-values "; } int $inConns = `optionVar -q copyAttrInConns`; if ($inConns == 1) { $cmd += "-inConnections -keepSourceConnections "; } else if ($inConns == 2) { $cmd += "-inConnections "; } if (`optionVar -q copyAttrOutConns`) { $cmd += "-outConnections "; } if (`optionVar -q copyContainerParent`) { $cmd += "-containerParentChild "; } if (`optionVar -q copyContainerRename`) { $cmd += "-renameTargetContainer "; } if (`optionVar -q copyAttrFromCB`) { string $attrs[] = `selectedChannelBoxAttributes`; for ($attr in $attrs) { $cmd += ("-attribute "+$attr+" "); } } $cmd += ("`findTransferValueTargets`"); return $cmd; } // // Procedure Name: // performTransferContainer // // Description: // Perform the copyAttr 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 optionBoxExample1 command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performTransferContainer(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: transferValuesOptions; break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }