Dynamic paths in Maya

Hi all,

I’m looking for a method of specifying a path via some sort of parameter expansion.

E.g. instead of c:\myfolder\myfile.png
I’d like to say $ROOT\myfile.png

So as to avoid including the root directory in the scene itself. The idea is to facilitate distributed work, for example by hosting the project in a Dropbox directory, where everyone has different locations at which Dropbox is located.

Does anyone know if this is possible, or know of an alternative technique?

Environment variables?
Maya actually does a pretty good job of resolving them on its own, and obviously Python has os.path.expandvars

Yes, resolving environment variables would be amazing.

I’m talking of course about paths as attribute values, such as the file-value of a texture node, or a reference-node.

cmds.setAttr(“mytexture.fileTextureName”, “%myvar%/texture.png”)

Such that I can save a scene, open it up from another environment where %myvar% is different, and thus a point to a different resolved path.

By the looks of it, it works just like that! Except variables are referenced via “$” on both Windows and Unix.

$ set ROOT=c:\myroot
$ maya

Then in Maya, set a file path to any node to:

$ROOT\myfile.png

I’m having trouble Googling this feature, does anyone know how long it’s been supported? In the Reference Editor, it gives you a preview of what a path containing environment variables resolves into. Is anyone using this to in production?

Yeah, we use environment variables for that.
Though the syntax is what you had in your first post.

For example one of our animation files would be referencing its rig from:
“$PROJECT_FILES/Rigs/Soldier_Rig_3p.ma”

Which references the its skinned mesh from:
“$PROJECT_FILES/Characters/Meshes/Soldier_Mesh_Skinned.ma”

Which could be referencing a texture:
“$PROJECT_FILES/Characters/Meshes/Soldier_Diffuse.TGA”

And as long as Maya can properly resolve these, and nobody decides to save them as resolved paths, they let folks work on the same files without having to enforce that everyone setup their Perforce workspaces in an identical manner. (Though to help keep these functioning, we’ve got a bunch of error checking scripts that will fix up the references paths, or at the very least let the user know that thing they just did is going to cause a headache for the next person wh uses the scene)

Amazing. Exactly what I was looking for. Thanks R.White!