Goal: Trying to catch a broken reference while opening a file, and fixing it using maya.api.OpenMaya (2.0 python api)
I’m using the addCheckFileCallback with a kBeforeCreateReferenceCheck to catch the MFileObject, and correct the bad path. However, its not going well from there. Found this post for 1.0 algorithm
In the pre 2.0 examples I can follow online, people are referring to the need to use MScriptUtil to set a bool so that the previous retcode knows to use the new MFileObject… (if i understand it correctly). 2.0 Docs refer to the pythonic way no longer requiring the MScriptUtil, and I don’t know if this is a hint of something I’m missing yet, or what. Below is my base algorithm.
# code snippets (nonfunctional code) import maya.api.OpenMaya as OpenMaya # function is receiving an extra var when called, its coming in always as None, just have a catch all for it called unknownVar) def fixReferencePaths(file_object, unknownVar) ref_path = file_object.rawFullName().encode("ascii") # convert from unicode to ascii fnd_path = go_find_file(ref_path) file_object.setRawFullName(fnd_path) # here online examples from pre 2.0 days say to use the MScriptUtil.setBool(retCode, True) # unsure what the 2.0 api equivalent might be or if even needed? def go_find_file(ref_path) # do some magic here, find file, convert it to maya safe path before return OpenMaya.MSceneMessage.addCheckFileCallback(OpenMaya.MSceneMessage.kBeforeCreateReferenceCheck, fixReferencePaths)
Side question: With the lack of 2.0 things I’m seeing online, is it just that people aren’t using it much? Will the 1.0 api be unsupported at some point in the future? There’s no particular reason I’m doing this with the 2.0 api other than if I’m going to learn something, I try to learn the latest.