// =========================================================================== // 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. // =========================================================================== // // NOTE: This is a modified version of cutCopyPaste.mel, based on the // version that shipped with Maya 2011. It provides some hooks // to extend the cut-copy-paste operations to work with MayaBullet. //--------------------------------------------------------------------------- // Returns 1 if any of the nodes in the list provided are Bullet shapes // Returns 0 otherwise //--------------------------------------------------------------------------- python( "import sys" ); python "import maya.app.mayabullet.MayaUtils as MayaUtils"; python "import maya.app.mayabullet.BulletUtils as BulletUtils"; global proc pasteScene(){ string $fileExt = ".mb"; if (`about -ltVersion`) { $fileExt = ".mlt"; } // determine temp directory string $tmpFile = "/maya_sceneClipBoard" + $fileExt; string $tmpdir = `getenv TMPDIR`; string $filePath = ($tmpdir + $tmpFile); // import scene string $newTransforms[] = `file -force -import -renameAll true -renamingPrefix "pasted_" -groupReference -returnNewNodes $filePath`; select -replace $newTransforms; select -replace `ls -sl -head 1`;} global proc cutCopyScene (int $cut){ string $fileExt = ".mb"; string $fileType = "mayaBinary"; if (`about -ltVersion`) { $fileExt = ".mlt"; $fileType = "mayaLT"; } // determine temp directory string $tmpFile = "/maya_sceneClipBoard" + $fileExt; string $tmpdir = `getenv TMPDIR`; string $filePath = ($tmpdir + $tmpFile); // export selected nodes file -force -exportSelected -constructionHistory true -channels true -expressions true -constraints true -shader true -type $fileType $filePath; // delete nodes if user asks for cut if ($cut){ delete; } } global proc cutCopyPaste (string $operation){ // $operation: cut // copy // paste // make sure generateChannelMenu has been sourced so channelBox commands work if (!`exists channelBoxCommand`){ source generateChannelMenu.mel; } // based on active panel, channelBox selection and selected nodes // determine what user wants to cut copy paste string $option = "none";; string $parameter; string $selection[] = `ls -sl`; // determine if active panel is animation based // this value should override the channelBox cut copy paste string $currentPanel = `getPanel -underPointer`; if( $currentPanel == "" ) { $currentPanel = `getPanel -withFocus`; } string $panelType = `getPanel -typeOf $currentPanel`; if( $panelType == "scriptedPanel" ) { $panelType = `scriptedPanel -q -type $currentPanel`; if ($panelType == "graphEditor" || $panelType == "dopeSheetPanel" || $panelType == "clipEditorPanel") { $option = $panelType; if( $panelType == "dopeSheetPanel" ) { $parameter = $currentPanel + "OutlinerSelection"; } else { $parameter = editorNameFromPanel( $currentPanel ); } } else { $option = "nodes"; } } // determine if anything is selected else if (size($selection)){ $option = "nodes"; // determine if attrs are selected in channelBox string $attrList[] = `channelBox -q -selectedMainAttributes mainChannelBox`; string $attrHistoryList[] = `channelBox -q -selectedHistoryAttributes mainChannelBox`; string $attrOutputList[] = `channelBox -q -selectedOutputAttributes mainChannelBox`; string $attrShapeList[] = `channelBox -q -selectedShapeAttributes mainChannelBox`; if ((size($attrList) != 0) || (size($attrHistoryList) != 0) || (size($attrOutputList) != 0) || (size($attrOutputList) != 0)){ $option = "channels"; } } else if (!size($selection) && $operation == "paste"){ $option = "nodes"; } switch ($option){ case "channels": if ($operation == "cut"){ channelBoxCommand -cut; } else if ($operation == "copy"){ channelBoxCommand -copy; } else { channelBoxCommand -paste; } break; case "graphEditor": if ($operation == "cut"){ performCutKeyArgList 1 {"3", $parameter, "1"}; } else if ($operation == "copy"){ performCopyKeyArgList 1 {"3", $parameter, "1"}; } else { performPasteKeyArgList 1 {"3", $parameter, "1"}; } break; case "dopeSheetPanel": if ($operation == "cut"){ performCutKeyArgList 1 {"0", $parameter, "2"}; } else if ($operation == "copy"){ performCopyKeyArgList 1 {"0", $parameter, "2"}; } else { performPasteKeyArgList 1 {"0", $parameter, "2"}; } break; case "clipEditorPanel": if ($operation == "cut"){ doCutClipArgList 1 { $parameter }; } else if ($operation == "copy"){ doCopyClipArgList 1 { $parameter }; } else { performPasteClip 0; } break; case "nodes": string $bulletNodes[] = python("BulletUtils.findSelectedBulletShapes()"); int $hasBulletNodes = size($bulletNodes) > 0; if ( $operation == "cut" ) { if ( $hasBulletNodes ) { python "MayaUtils.handlePreCut()"; } cutCopyScene 1; } else if ( $operation == "copy" ) { if ( $hasBulletNodes ) { python "MayaUtils.handlePreCopy()"; } cutCopyScene 0; if ( $hasBulletNodes ) { python "MayaUtils.handlePostCopy()"; } } else { python "MayaUtils.handlePrePaste()"; pasteScene; python "MayaUtils.handlePostPaste()"; } break; case "none": // nothing selected - nothing required but a warning warning( (uiRes("m_bulletCutCopyPaste.kNothingSelected")) ); break; } }