March 2019: ewertb.soundlinker.com is getting relocated to ewertb.mayasound.com, please update your bookmarks.

MEL How-To #70

Back · Previous · Next Maya

How can I intercept a Save or Save As operation?

Along the evolution of a robust in-house toolset for Maya you will inevitably come across the need to perform a set of actions each time someone saves a scene from Maya. This could be to initiate a process to integrate the saved data into the production pipeline, or something simpler like generating a log file containing information about the scene.

I have found that the best way to reliably integrate this into Maya's operation is to edit the "pv_performAction.mel" script; e.g.:

\AW\Maya3.0\scripts\others\pv_performAction.mel

Add your custom operation(s) at the necessary stage within the long series of ‘if..else’ statements.

For the "Save As" function this would be in or about Line 245 (using Maya v3.0.1), amongst:

if ($OKToSave) {
  if ($gv_operationMode == "SaveAs") {
  // ...
    evalEcho($cmd);
  // ...
    addRecentFile ($theSavedFile, $fileType);

// *** Add call to your MEL procedure here ***

  } else if ($gv_operationMode == "ExportActive") {

When modifying Maya's own internal scripts, I recommend saving the modified versions in a different location, leaving the original intact. If your company's workstations share a common drive mapping, create a "scripts" folder on this drive and save the new MEL here. Set the MAYA_SCRIPT_PATH for each workstation to include this mapped drive, specifying your folder earlier in the list than Maya's default paths. Save the modified "pv_performAction.mel" into the mapped folder and it will conveniently override the default behaviour.

Caution: The "pv_performAction.mel" script typically changes with each version of Maya, so if you upgrade Maya you'll want to move your custom functionality into the script applicable to the version you are running. Wrap your enhancements in big bold comments so they're easy to spot.

Wednesday, August 29, 2001