Version Control Within Maya

 

 

well, this section is not specifically about the exporter as such, but more about ways in which we can get maya to communicate with version control software such as VSS or CVS.

The code presented here is not full production ready source, however it should give you enough insight to get your Art Department using version control in the same way you would in Visual C++.

 

 

 

 

A Few Global Basics

If in the script editor of Maya you execute the command (use the little enter key to execute mel script).

print `env`;

Maya will print a list of all of the global variables within mel. Now, somewhere within that list is a variable called, $gMainFileMenu. This variable is the name of the main file menu within Maya.

Now, as a test, if you open a clean version of Maya, you can type in the script editor

menu -edit -label "MyFileMenu" $gMainFileMenu

You may now notice that the main File menu is now labelled as "MyFileMenu". Well, this is quite interesting, it basically means that we can edit and change any of the user interface features we want to.

There is one thing that both VSS and CVS have in common, and that is that they can both be run from the command line. Within mel script we have the ability to make use of pipes and system calls, so we essentially have a way of accessing version control within Maya.

Knowing that we can change the user interface, and that we can pipe commands to our version control software, there is no reason why we cannot make the following changes to Maya's File menu :

  1. When the "Open File" menu option is selected, we would like to know if the file is checked out or not. If it's not checked out we can use a prompt dialog to ask the user if they would like to check it out.
  2. When the "Save Scene" menu option is selected, we can ask the user if they would like to check the file in.
  3. When the "Save Scene As" menu item is selected, we can ask the user if they would like to add the new file into version control.

We could in addition consider the possibility of adding in

  • data verification tests when saving files
  • Check In / Check Out menu items
  • One press view options etc.
 

 

 

A Little bit of Mel

We basically want to replace the way in which the open, save and save as menu items work. By default, these 3 menu items call OpenScene, SaveScene and SaveSceneAs respectively.

We can create three mel procedures to replace the way in which the default functions work (in our case, we will only be adding additional functionality).

Once we have defined our mel procedures, we can use the menuItem command to edit the existing menu items "openProject", "saveItem" and "saveAsItem".

 


 

 


// this procedure will be called when a new file
// is opened

global proc OpenProjectCommand() {

 
print("-- OpenProjectCommand --\n");
OpenScene
;

}

// this procedure will be called when a file is saved
global proc SaveProjectCommand() {

  print("-- SaveProjectCommand --\n");
SaveScene;

}

// this procedure will be called when save as
// is selected

global proc SaveAsProjectCommand() {

  print("-- SaveAsProjectCommand --\n");
SaveSceneAs;

}

menuItem -e -c "OpenProjectCommand" "openProject";
menuItem -e -c "SaveProjectCommand" "saveItem";
menuItem -e -c "SaveAsProjectCommand" "saveAsItem";

 

 

Returning to the Default Behaviour

At any time we can still revert to the default behaviour using the script on the right.

 

 


 

 

menuItem -e -c "OpenScene" "openProject";
menuItem -e -c "SaveScene" "saveItem";
menuItem -e -c "SaveSceneAs" "saveAsItem";

 

 

Retrieving Scene Information

If we are going to be checking in and checking out files, we will need to be able to access the filename of the current scene.

 


// print the scene name
print `file -q -sceneName`;

// print the full filename
print `file -q -exn`;


 

 

The mel MessageBox()

Under Win32 we can use the MessageBox() function to create a simply query dialog. A similar functionality exists in mel as the confirmDialog.

 

 

 

 

 

 


// create a confirm dialog box

$result = `confirmDialog -title "The Title"
-message "Yes or No?"
-button "Yes"
-button "No"
-defaultButton "Yes"
-cancelButton "No"
-dismissString "No"`;

// check the result
if( $result == "No" )
{

  print("NO!!!\n");

} else {

  print("YES!!!\n");

}

 

 

Using Pipes within mel

Ultimately which version control system you use, is going to determine what commands you require in order to check in and check out files.

Probably the best way of doing this (because you can read back the returned information) is to use a pipe. The example script here simply uses a pipe to perform "dir".

 


// create a pipe to execute "dir"

$pipe = popen( "dir", "r" );

// keep reading until the pipe finishes
while ( !feof( $pipe ) ) {

  // read a line at a time and print it
print
`fgetline( $pipe )`;

}

// close the pipe
pclose( $pipe );

 

 

 

The Finished Script

You can download a working version of the script here. I have left the functions for you to finish off to query your version control system.

If you want the script to run at the start up of Maya, then save it in the maya scripts directory

(my documents/maya/scripts/)

as "userSetup.mel". This will now be run every time maya is opened.

 


 

 

What Next?

FileIO in the Maya API

Animation Data

index

Rob Bateman [2004]

[HOME] [MEL] [API]