Maya pop-up window informing the user that pasting in the "modelPanel" can be bad. Asks if they wish to continue or not

Fixing Maya’s most destructive keyboard shortcut

Autodesk’s Maya is full of keyboard shortcuts, but none of them are as the potentially destructive as paste – ctrl-v.

I finally reached a point recently where I’d lost enough time to this, so I decided to fix it.

This post is based on my original tweet thread here.

But why is pasting in Maya such a bad thing?

Maya’s copy and paste doesn’t just run off of Window’s clipboard. It’s not a massive surprise as the things you’d normally copy inside Maya aren’t text and images. There are still text fields in Maya, so text copy and paste does still work here normally, but there are a greater number of contexts in which you’d want similar functionality on Maya’s own data types.

When you copy something from Maya’s scene view – a model for example – Maya creates a new temporary scene file on disk with whatever was selected at the time of copying. The next time you paste, the entirety of that scene file is added rather unceremoniously into your scene. Every new node added to your scene also has its name prefixed with pasted__. This includes connected nodes, such as materials, constraints etc.

Back to the answer to the above question – why is it such a bad thing? No undo, and unneeded node duplication, leading to messy scenes.

A very common occurrence (for me at least) is copying and pasting in the wrong context. Either I’d meant to have selected a text field and failed or thought I’d alt-tab‘d away from Maya and hadn’t. Given that most of the time when I’m in Maya I’m rigging, an accidental paste for me includes a near complete copy of the rig I’m working on, complete with locked nodes, layers, and a bunch of hidden cruft.

In this scenario, it’s faster often to lose work and revert to an earlier version then unpick and delete all of the extra junk…

Why not disable it compeltely?

Popup-box in Maya reading
"Pasting disabled,
You disabled pasteing because it's about the worst thing you can do in Maya!"
The nuclear option, complete with typos

Thankfully Maya has a highly customisable hotkey editor so we can hijack our paste command and replace it with any code we want. But the biggest issues with this approach are losing copy/paste across the entirety of Maya – script editor, animation graph – and for the odd occasion when it’s actually useful in the modelView.

Only the hotkey editor?

This is Maya, there are many ways to customise your own personal torment. It’s possible to override Maya’s global proc with a custom one in a user scripts directory. This would be how I’d approach it when I have time / enough demand from the team to roll it out as part of the art pipeline.

The “safe” way to do it

“Safe” being an important word here. The last thing you want is to be staring down the barrel of a deadline with some flippant script change your made for “internet points” tripping you up. Or even worse, your random script made its way to someone less informed and it’s tripping them up…

Screenshot of windows explorer showing the file-path to Maya's cutCopyPast.mel file.
The path reads
Program Files\Autodesk\Maya2022\scripts\startup
Where our offender lives when it’s not making us trouble

Let’s see first how Maya does copy & paste first. The paste command lives in “mel-land” – a cursed place which thankfully is human readable. In fact, moans about mel aside, being able to see what most of Maya’s commands are doing is really handy, especially at times like this.

Screenshot of mel script from cutCopyPaste.mel.

Snippet depicts a 7-case switch statement in which Maya handles different copy and paste functionality depending on the context where it's being called.

Towards the bottom of this screenshot in the "nodes" case, the function call "pasteScene" is underlined
Underlined; the offending function call for pasting in the temporary scene

The above snippet of mel shows a chunky switch statement where Maya figures out what to do with our ctrl-x/c/v behaviour. I’ve underlined the function call which is bringing my misery. The switch case is set to "nodes" if we don’t have one of 5 other panels focused in Maya.

I could just comment out this command here, but I don’t want to alter Maya’s install as this won’t survive uninstall/reinstall. Definitely not safe, also a more awkward “fix” to move to the rest of the team if needed.

But now I know of Maya’s criteria for its own changing behaviour, I can reverse engineer it pretty easily.

The mel command for getPanel -underPointer or -withFocus returns the current panel we care about. Sadly running this command in with the graphEditor in focus via python throws # RecursionError: maximum recursion depth exceeded while calling a Python object #, so we’re stuck in mel for this which is a pain.

The final code

A screenshot of Maya with the mel script in the hotkey editor for the changes I've made to pasting.

Pictured to the right, a popup asking if the user still wants to paste in the model panel.
Updated shortcut for “paste” in action

In the end, quite a straight-forward adaption of Maya’s own cutCopyPaste.mel. If we paste into a panel which isn’t of the type "scriptedPanel", we prompt the user that bad things might happen if they continue to paste. No functionality broken, just an extra safety net.

Otherwise fall straight through into the regular paste function.

… I’ll paste mel snippet when I’m next at my work PC where it’s located.