Thursday, November 24, 2016

Maya Tips & Tricks - Using directories outside of the maya project stucture (relative path)

One of the main purpose to use Maya project structure to have the ability to reference directories locally. That means the project can be relocated. Let's say we have the Maya project root folder:


So the Maya default project structure look like this:

Beside the folders there is the workspace.mel file which describes the file rules within that Maya projects. In practice that means if you have Maya running and set this project (File menu / Set Project...) and you hit the Open Scene... from the File menu the file browser pops up pointing to directory below:


The workspace.mel file contains a mel command to address the file rule for Maya scene files:

workspace -fr "scene" "scenes";

More precisely there are two more file rule because of the maya scene file extensions. One for the .mb and one for the .ma extension:

workspace -fr "mayaAscii" "scenes";
workspace -fr "mayaBinary" "scenes";

The absolute scenes path is generated like this based on the current file rule:

project root  + /scenes

So Maya referencing the scenes directory below the Maya project root folder. Since than it does not matter where the Maya project is in the directory structure because inside the project it will be always valid.
But in studio scenario we can pretend that for eg. the Maya renders should be elsewhere than below the maya project as the default file rule describe it:

workspace -fr "images" "images";

Without any adjustment if we want to render an image it will look like this on Maya render settings panel:

As before the absolute scenes path generated like this based on the current file rule:

project root  + /images (the file name is the scene name by default.)

So as mentioned before usually we want to use an external directory to output the renders so the compositors don't have to look up it inside a Maya project but a directory with more general purpose. So the render (images) directory should be something like this:


We can avoid to use that absolute path. Maya can use relative path as a file rule. Just have to use the "../" syntax. It tells to Maya to go one directory up relative to the root folder. My super cool explanation picture:

To reference the elements directory the file rule will look like this:

 workspace -fr "images" "../elements";

My experience is that if I directly edit the workspacel.mel file maya only recognize that change after a restart. To edit the file rule via Project Window from the File menu it works fine.

Using relative paths means your project relocatable but the maya project itself depends on the outside directory structure.

Further reading.