Hiya Back!
I found this post awhile back addressing this:
I couldn’t get it to work without some extra lines forcing a few things here and there either.
You’ll have to write supporting code on locating your missing references.
And I hope you have better luck than I did, once I spliced in my own function to search, and replace when one was missing, I couldn’t return back to the default behavior to prompt the user to locate it themselves. My maya api knowledge is practically nill so I couldn’t take this much further myself.
Head’s up, it says OldOpenMaya because I attempted this with 2.0 and had less luck.
PS sorry about bad formatting I’m awful in forums, somehow I can’t keep the initial indention in the code snippet.
import maya.OpenMaya as OldOpenMaya
def fixReferencePaths(retCode, file_object, clientData):
try:
orig_path = file_object.fullName()
ref_path = file_object.rawFullName().encode("ascii")
if not os.path.exists(ref_path):
# find path logic
fnd_path = find_file(ref_path, search_root=get_project_path()) #find_file is a custom method
fnd_path = convert_path_to_maya_path(fnd_path)
if os.path.exists(fnd_path):
file_object.setRawFullName(fnd_path)
OldOpenMaya.MScriptUtil.setBool(retCode, True)
print('Could not locate: {}\n Used: {}.'.format(ref_path, fnd_path))
return
else:
file_object.fullName = orig_path
OldOpenMaya.MScriptUtil.setBool(retCode, True)
return
except:
message = 'ERROR: Count not run fix reference paths'
print(message)
pm.warning(message)
return
def enableFixReferences():
OldOpenMaya.MSceneMessage.addCheckFileCallback(OldOpenMaya.MSceneMessage.kBeforeCreateReferenceCheck,
fixReferencePaths)