When working on multiple projects you might want to use assets from other projects.
Very often a file referencing pipeline makes this difficult though as Maya stores file references with absolute paths when you are not using Maya projects.
To avoid this you can hijack the Referencing procedure with a callback.
The callback triggers any function you define.
In the function you have access to the file path of the reference to do some checks and you can cancel the loading of the reference or manipulate the path to your liking.
Create a function somewhere in your pipeline.
Your function needs 3 parameters:
parameter 1 is the return code (a boolean to approve or cancel the reference load operation)
parameter 2 is the file object which holds the path and file information
parameter 3 is client data which you can pass in to your function from the callback
def callbackFunction(retCode, fileObject, clientData):
# printing the original file path
print "Original file path %s" % fileObject.rawFullName()
# create a variable for the new file path
# maybe create some logic for that or even a condition whether to
# manipulate the path or keep the existing one
newFilePath = "C:/tmp/newFile.ma"
# set the file path to be loaded if you want to modify it
# here you can define whether the file should be loaded or
# whether the reference should be skipped
to create the callback for the file Reference use this code:
import maya.OpenMaya as om
The function will be executed every time maya is about to load a reference.
You can even ask the user to browse for a new file when the current file is not in your project path for instance.
In the pipeline I am working on I inform the person that the file that is being referenced is not in the project path and ask, whether the user wants to load that file anyway or point to a new file.
This makes copying assets from one project to the other easier and also people will be warned that they are about to load a rig from a different project when opening a copied animation.
Is the popup annoying? Yes, maybe. But it definitely helps you softly enforcing all dependencies being copied to the right places 🙂