Autodesk’s Maya is full of keyboard shortcuts, but none of them are as the potentially destructive as paste –
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?
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
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…
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.
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.
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
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.