2 Custom file resolver derived from MPxFileResolver that handles
4 When this resolver is active, URI file paths using the 'file:///'
5 scheme will be processed using methods on this class.
6 Refer to MPxFileResolver for more information about custom file resolvers.
8 To use, make sure that adskFileSchemeResolver.py is in
9 your MAYA_PLUG_IN_PATH then do the following:
13 maya.cmds.loadPlugin("adskFileSchemeResolver.py")
14 # Once loaded, Maya will call the resolver methods in this plug-in when
15 # a URI file path is encountered during file resolution processing
16 # (file open, setAttr, etc.)
18 maya.cmds.unloadPlugin("adskFileSchemeResolver")
19 # Maya will no longer have access to this file
20 # resolver to handle URI file paths using the 'file:///' scheme
25 import maya.OpenMaya
as OpenMaya
26 import maya.OpenMayaMPx
as OpenMayaMPx
27 import maya.cmds
as cmds
31 class adskFileSchemeResolver(OpenMayaMPx.MPxFileResolver):
33 This custom plug-in resolver handles the 'file' uri scheme.
34 The resolution algorithm will return the fully qualified file path
35 obtained from the URI directory and filename elements.
38 kPluginURIScheme =
"file"
39 kPluginResolverName =
"adskFileSchemeResolver"
42 OpenMayaMPx.MPxFileResolver.__init__(self)
45 return(self.kPluginURIScheme)
47 def resolveURI(self,uriFilePath,mode):
51 resolvedFilePath = uriFilePath.getPath()
52 return resolvedFilePath
57 return OpenMayaMPx.asMPxPtr( adskFileSchemeResolver() )
61 return 'adskFileSchemeResolver'
66 def initializePlugin(plugin):
67 pluginFn = OpenMayaMPx.MFnPlugin(plugin)
69 pluginFn.registerURIFileResolver( adskFileSchemeResolver.kPluginResolverName,
70 adskFileSchemeResolver.kPluginURIScheme,
71 adskFileSchemeResolver.theCreator )
73 sys.stderr.write(
"Failed to register custom resolver: %s for scheme: %s\n" %
74 (adskFileSchemeResolver.kPluginResolverName,
75 adskFileSchemeResolver.kPluginURIScheme ))
79 def uninitializePlugin(plugin):
80 pluginFn = OpenMayaMPx.MFnPlugin(plugin)
82 pluginFn.deregisterURIFileResolver(adskFileSchemeResolver.kPluginResolverName)
85 "Failed to deregister custom file resolver: %s\n" %
86 adskFileSchemeResolver.kPluginResolverName)