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.
1 |
MSceneMessage.addCheckFileCallback |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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 fileObject.setRawFullName(newFilePath) # here you can define whether the file should be loaded or # whether the reference should be skipped OpenMaya.MScriptUtil.setBool(retCode, True) |
[…]