// =========================================================================== // 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 publish an attribute to a container. // // // 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) { if ($forceFactorySettings || !`optionVar -exists publishWhichAttrs`) { // Default is: publish selected channel box attributes // // Note: this optionVar is also set by the channel box // edit menu (generateCBEditMenu.mel) // optionVar -intValue publishWhichAttrs 0; } if ($forceFactorySettings || !`optionVar -exists publishAttrName`) { // name plus numerical suffix optionVar -intValue publishAttrName 0; } if ($forceFactorySettings || !`optionVar -exists publishAttrPrefix`) { // custom prefix optionVar -stringValue publishAttrPrefix ""; } } // // Procedure Name: // publishAttributeSetup // // 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 publishAttributeSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars( $forceFactorySettings ); setParent $parent; int $whichAttrs = `optionVar -query publishWhichAttrs`; switch ($whichAttrs) { case 0: { radioButtonGrp -edit -sl 1 publishCBWidget; break; } case 1: { radioButtonGrp -edit -sl 1 publishKeyableWidget; break; } case 2: { radioButtonGrp -edit -sl 1 publishInConnWidget; break; } case 3: { radioButtonGrp -edit -sl 1 publishSelectedAttrsWidget; break; } } int $nameConvention = `optionVar -query publishAttrName`; switch ($nameConvention) { case 0: { radioButtonGrp -edit -sl 1 attrNameWidget; break; } case 1: { radioButtonGrp -edit -sl 1 nodeNameWidget; break; } case 2: { radioButtonGrp -edit -sl 1 prefixWidget; break; } case 3: { radioButtonGrp -edit -sl 1 customNameWidget; break; } } string $prefix = `optionVar -query publishAttrPrefix`; textFieldGrp -e -text $prefix prefixStringGrp; textFieldGrp -e -enable ($nameConvention > 1) prefixStringGrp; } // // Procedure Name: // publishAttributeCallback // // 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 publishAttributeCallback(string $parent, int $doIt) { setParent $parent; int $whichAttrs = 0; if (`radioButtonGrp -q -sl publishCBWidget`) { $whichAttrs = 0; } else if (`radioButtonGrp -q -sl publishKeyableWidget`) { $whichAttrs = 1; } else if (`radioButtonGrp -q -sl publishInConnWidget`) { $whichAttrs = 2; } else if (`radioButtonGrp -q -sl publishSelectedAttrsWidget`) { $whichAttrs = 3; } optionVar -intValue publishWhichAttrs $whichAttrs; int $nameConvention = 0; if (`radioButtonGrp -q -sl attrNameWidget`) { $nameConvention = 0; } else if (`radioButtonGrp -q -sl nodeNameWidget`) { $nameConvention = 1; } else if (`radioButtonGrp -q -sl prefixWidget`) { $nameConvention = 2; } else if (`radioButtonGrp -q -sl customNameWidget`) { $nameConvention = 3; } optionVar -intValue publishAttrName $nameConvention; if ($nameConvention > 1) { optionVar -stringValue publishAttrPrefix `textFieldGrp -q -text prefixStringGrp`; } if ($doIt) { performPublishAttribute 0; addToRecentCommandQueue "performPublishAttribute 0" "Publish Attribute"; } } // // Procedure Name: // publishAttributeOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc publishAttributeOptions() { // Name of the command for this option box. // string $commandName = "publishAttribute"; // 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("container"); // 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 DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Turn on the wait cursor. // waitCursor -state 1; tabLayout -tabsVisible 0 -scrollable 1; string $parent = `columnLayout -adjustableColumn 1`; columnLayout; radioButtonGrp -label (uiRes("m_performPublishAttribute.kPublish")) -label1 (uiRes("m_performPublishAttribute.kSelectedChannelBox")) publishCBWidget; radioButtonGrp -label "" -label1 (uiRes("m_performPublishAttribute.kAllKeyable")) -scl publishCBWidget publishKeyableWidget; radioButtonGrp -label "" -label1 (uiRes("m_performPublishAttribute.kIncomingConnections")) -scl publishCBWidget publishInConnWidget; radioButtonGrp -label "" -label1 (uiRes("m_performPublishAttribute.kSelectedAttributes")) -scl publishCBWidget publishSelectedAttrsWidget; radioButtonGrp -label (uiRes("m_performPublishAttribute.kAttributeName")) -label1 (uiRes("m_performPublishAttribute.kAddANumber")) -onc "textFieldGrp -e -enable 0 prefixStringGrp" attrNameWidget; radioButtonGrp -label "" -label1 (uiRes("m_performPublishAttribute.kPrefixWithNode")) -scl attrNameWidget -onc "textFieldGrp -e -enable 0 prefixStringGrp" nodeNameWidget; radioButtonGrp -label "" -label1 (uiRes("m_performPublishAttribute.kPrefixWithString")) -scl attrNameWidget -onc "textFieldGrp -e -enable 1 prefixStringGrp" prefixWidget; radioButtonGrp -label "" -label1 (uiRes("m_performPublishAttribute.kCustomName")) -scl attrNameWidget -onc "textFieldGrp -e -enable 1 prefixStringGrp" customNameWidget; // used for custom name or prefix // textFieldGrp -label (uiRes("m_performPublishAttribute.kCustomString")) prefixStringGrp; setParent ..; separator; // 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 // 'Create' 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_performPublishAttribute.kPublishAttributeOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "PublishAttribute" ); // 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 = "optionBoxExample1"; setOptionVars(false); int $nameConvention = `optionVar -query publishAttrName`; string $customString = ($nameConvention > 1) ? `optionVar -query publishAttrPrefix` : ""; $cmd = ( "doPublishAttribute 1 { \"" + `optionVar -query publishWhichAttrs` + "\", " + "\"" + $nameConvention + "\", " + "\"" + $customString + "\" " + " } " ); return $cmd; } // // Procedure Name: // performPublishAttribute // // Description: // Perform the create container 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 performPublishAttribute(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: publishAttributeOptions; break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }