Skip to content

Instantly share code, notes, and snippets.

@RedForty
Created October 9, 2017 06:02
Show Gist options
  • Save RedForty/1096ea845e0302b345506f045c8ecdda to your computer and use it in GitHub Desktop.
Save RedForty/1096ea845e0302b345506f045c8ecdda to your computer and use it in GitHub Desktop.
Working with relative paths in the reference editor
import os.path
import maya.cmds as cmds
import maya.mel as mel
import maya.OpenMaya as OpenMaya
mel.eval('string $MyScenes; \
putenv $MyScenes "C:/Users/Admin/Desktop/fairy/"')
def foo(retCode, fileObject, clientData):
print "Callback was given %s" % fileObject.rawFullName()
rel = "$MyScenes/"
rel = rel + (os.path.basename(fileObject.rawFullName()))
print "Callback changed this to %s" % rel
fileObject.setRawFullName(rel)
OpenMaya.MScriptUtil.setBool(retCode, True)
id = OpenMaya.MSceneMessage.addCheckFileCallback(OpenMaya.MSceneMessage.kBeforeReferenceCheck, foo)
# for deleting the callback
OpenMaya.MMessage.removeCallback(id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment