// =========================================================================== // 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 create a camera layer multi-attribute for a // given cameraSet node. // proc string getNextAvailableLayer(string $nodeName) { // Get all of the connectable cameraLayerInfo attributes. string $allAttrs[] = `listAttr -multi -connectable ($nodeName + ".cameraLayer")`; int $i; int $c = -1; string $buffer[]; for ($i=0; $i < size($allAttrs); $i++) { tokenize($allAttrs[$i], "[]", $buffer); if (size($buffer) == 2) $c = $buffer[1]; } return ($c + 1); } // // Procedure Name: // createSetSetup // // 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 createCameraLayerSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setParent $parent; optionMenuGrp -e -enable true cameraLayerCameraListWidget; } // // Procedure Name: // createCameraLayerCallback // // 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 createCameraLayerCallback(string $parent, string $cameraSet, int $doIt) { setParent $parent; layoutDialog -dismiss ""; if ($doIt) { performCreateCameraLayer $cameraSet 0; addToRecentCommandQueue ("performCreateCameraLayer " + $cameraSet + " 0") "Create Camera Layer"; } } // // Procedure Name: // createCameraLayerDialog // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // global proc createCameraLayerDialog(string $cameraSetName) { // Name of the command for this option box. // string $commandName = "createCameraLayer"; // Build the dialog actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // Turn on the wait cursor. // waitCursor -state 1; // Get the dialog's formLayout. // string $form = `setParent -q`; // layoutDialog's are not resizable, so hard code a size here, // to make sure all UI elements are visible. // formLayout -e -width 400 $form; string $instruct1 = `text -align "left" -label (uiRes("m_performCreateCameraLayer.kCreateCameraLayerInstruct1"))`; string $instruct2 = `text -align "left" -label (uiRes("m_performCreateCameraLayer.kCreateCameraLayerInstruct2"))`; // Create an option menu listing the cameras // optionMenuGrp -label (uiRes("m_performCreateCameraLayer.kCamera")) -width 250 cameraLayerCameraListWidget; python( "from maya.app.stereo import stereoCameraRig" ); string $stereoCameraArray[] = python( "stereoCameraRig.listRigs( True )" ); string $temp[] = `ls -cameras`; int $tempCount = size($temp); for ($i = 0; $i < $tempCount; $i++) { string $rel[] = `listRelatives -fullPath -parent $temp[$i]`; // Remove the "|" in the string. // int $len = size($rel[0]); $temp[$i] = `substring $rel[0] 2 $len`; } for ($stereo in $stereoCameraArray) { $temp[size($temp)] = $stereo; } string $cameraArray[] = `sort $temp`; int $cameraCount = size($cameraArray); int $pp; // Duplicates can sneak into the list if the default stereo camera // rig is used. We test for this by looking at the previous item // added in the list. // string $last = ""; for ($pp = 0; $pp < $cameraCount; $pp++) { if (`objectType -isAType "transform" $cameraArray[$pp]`) { if ($last != $cameraArray[$pp]) { menuItem -label $cameraArray[$pp]; $last = $cameraArray[$pp]; } } } // See if one of the cameras is currently selected. If so, make it the current menu item. string $sc, $selCams[] = `ls -sl`; int $foundCam = false; $cameraArray = `optionMenuGrp -q -itemListLong cameraLayerCameraListWidget`; $cameraCount = size($cameraArray); for ($sc in $selCams) { for ($pp = 0; $pp < $cameraCount; $pp++) { if (`menuItem -q -label $cameraArray[$pp]` == $sc) { $foundCam = true; optionMenuGrp -e -select ($pp+1) cameraLayerCameraListWidget; break; } } if ($foundCam) break; } setParent $form; // Turn off the wait cursor. // waitCursor -state 0; string $b1 = `button -width 100 -l "Cancel" -c ($callback + " " + $form + " " + $cameraSetName + " 0")`; string $b2 = `button -width 100 -l "Create Layer" -c ($callback + " " + $form + " " + $cameraSetName + " 1")`; int $spacer = 10; int $top = 5; int $edge = 5; formLayout -e -attachForm $instruct1 "top" $edge -attachForm $instruct1 "left" $edge -attachForm $instruct1 "right" $edge -attachControl $instruct2 "top" 2 $instruct1 -attachForm $instruct2 "left" $edge -attachForm $instruct2 "right" $edge -attachControl cameraLayerCameraListWidget "top" $spacer $instruct2 -attachControl $b1 "top" $spacer cameraLayerCameraListWidget -attachForm $b1 "left" $edge -attachForm $b1 "bottom" $edge -attachControl $b2 "top" $spacer cameraLayerCameraListWidget -attachForm $b2 "right" $edge -attachForm $b2 "bottom" $edge $form; // Set the current values of the dialog. eval (($setup + " " + $form + " " + 0)); } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd(string $cameraSetNode) { string $cmd = "optionBoxExample1"; string $cameraName = "persp"; if (`optionMenuGrp -exists cameraLayerCameraListWidget`) { $cameraName = `optionMenuGrp -q -v cameraLayerCameraListWidget`; } $cmd = "$createCameraLayerResult = `createCameraLayerCmd " + $cameraSetNode + " " + $cameraName + "`;"; return $cmd; } // // Procedure Name: // createCameraLayerCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // global proc createCameraLayerCmd(string $cameraSetNode, string $cameraName) { // create the cameraSet command string and execute it. If a cameraName is // not specified, use the persp camera. if (size($cameraName)) eval("cameraSet -e -appendTo -camera " + $cameraName + " " + $cameraSetNode); else eval("cameraSet -e -appendTo -camera persp " + $cameraSetNode); refresh -f; } // // Procedure Name: // performCreateCameraLayer // // Description: // Perform the create camera layer 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 performCreateCameraLayer(string $cameraSetName, int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Get the command. // $cmd = `assembleCmd $cameraSetName`; // Execute the command with the option settings. // evalEcho($cmd); break; // Show the dialog. // case 1: layoutDialog -title (uiRes("m_performCreateCameraLayer.kCreateCameraLayerDialog")) -ui ("createCameraLayerDialog " + $cameraSetName); break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd $cameraSetName`; break; } return $cmd; }