// =========================================================================== // 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. // =========================================================================== // Procedure Name: // replaceEditor // // Description: // replace the editor under the pointer with the specified editor // // Input Arguments: // string $replacementEditor: name of the new editor e.g. graphEditor1 // string $windowCommand: command to open the new editor in a window e.g. GraphEditor // // Return Value: // None. // global proc replaceEditor (string $replacementEditor, string $windowCommand) { string $currentPanel = `getPanel -underPointer`; //check if in a window string $window = ($currentPanel + "Window"); int $windowExists = `workspaceControl -query -exists $window`; if ($windowExists){ string $newWindow = ($replacementEditor + "Window"); int $newControlStateExists = `workspaceControlState -exists $newWindow`; if ($newControlStateExists){ int $h = `workspaceControl -query -height $window`; int $w = `workspaceControl -query -width $window`; workspaceControlState -edit -widthHeight $w $h $newWindow; } eval $windowCommand; // Take the other editor's current tab position to keep the tab at // the same place it was. string $tabPosition = `workspaceControl -query -tabPosition $window `; workspaceControl -edit -tabToControl $window -1 -tabPosition $tabPosition false $newWindow; workspaceControl -edit -close $window ; } else { int $windowExists = `window -exists $window`; if ($windowExists){ int $tlc[] = `window -q -topLeftCorner $window`; int $w = `window -q -width $window`; int $h = `window -q -height $window`; // for Mac Qt 4.8+ Maya will crash on a corrupt changeGuard call // to prevent this we'll hide the current window before switching to the new one if ( `about -mac` ) { window -e -vis 0 $window; } else { // For windows and linux, // If there is dpi scaling, querying the width and height will be multiplied // by dpi scaling value. So we need to divide the width and height by dpi // scaling value to get the right size for creating new window. // IMPORTANT: In the future, if the behavior changes (if querying // width and height returns non-scaled value), then this script has // to be updated accordingly. float $scaleValue = `mayaDpiSetting -q -realScaleValue`; if ($scaleValue != 1.0 && $scaleValue > 0.0) { $w = $w / $scaleValue; $h = $h / $scaleValue; } } string $newWindow = ($replacementEditor + "Window"); eval $windowCommand; window -e -topLeftCorner $tlc[0] $tlc[1] $newWindow; window -e -width $w $newWindow; window -e -height $h $newWindow; } else { scriptedPanel -e -rp $currentPanel $replacementEditor; } // after a tearoff, sometimes, the workspaceControl stays behind, we close it here. string $newWindow = ($replacementEditor + "Window"); int $workspaceWindowExists = `workspaceControl -query -exists $newWindow`; if($workspaceWindowExists){ workspaceControl -e -close $newWindow; } } }