Python API 2.0 Reference
adskFileSchemeResolver.py
1 """
2 Custom file resolver derived from MPxFileResolver that handles
3 the URI 'file' scheme.
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.
7 
8 To use, make sure that adskFileSchemeResolver.py is in
9 your MAYA_PLUG_IN_PATH then do the following:
10 
11 # Load the plug-in
12 import maya.cmds
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.)
17 # Unload the plug-in
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
21 
22 """
23 
24 import sys
25 import maya.OpenMaya as OpenMaya
26 import maya.OpenMayaMPx as OpenMayaMPx
27 import maya.cmds as cmds
28 
29 
30 # 'file' scheme resolver
31 class adskFileSchemeResolver(OpenMayaMPx.MPxFileResolver):
32  """
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.
36  """
37 
38  kPluginURIScheme = "file"
39  kPluginResolverName = "adskFileSchemeResolver"
40 
41  def __init__(self):
42  OpenMayaMPx.MPxFileResolver.__init__(self)
43 
44  def uriScheme(self):
45  return(self.kPluginURIScheme)
46 
47  def resolveURI(self,uriFilePath,mode):
48  # Retrieve the path (directory and filename) from the URI
49  # Resolved path is this fully qualified path
50  # Note: This resolver does not need to use the resolver mode
51  resolvedFilePath = uriFilePath.getPath()
52  return resolvedFilePath
53 
54  @staticmethod
55  # Creator for the proxy instance
56  def theCreator():
57  return OpenMayaMPx.asMPxPtr( adskFileSchemeResolver() )
58 
59  @staticmethod
60  def className():
61  return 'adskFileSchemeResolver'
62 
63 
64 
65 # Initialize the script plug-in
66 def initializePlugin(plugin):
67  pluginFn = OpenMayaMPx.MFnPlugin(plugin)
68  try:
69  pluginFn.registerURIFileResolver( adskFileSchemeResolver.kPluginResolverName,
70  adskFileSchemeResolver.kPluginURIScheme,
71  adskFileSchemeResolver.theCreator )
72  except:
73  sys.stderr.write( "Failed to register custom resolver: %s for scheme: %s\n" %
74  (adskFileSchemeResolver.kPluginResolverName,
75  adskFileSchemeResolver.kPluginURIScheme ))
76  raise
77 
78 # Uninitialize the script plug-in
79 def uninitializePlugin(plugin):
80  pluginFn = OpenMayaMPx.MFnPlugin(plugin)
81  try:
82  pluginFn.deregisterURIFileResolver(adskFileSchemeResolver.kPluginResolverName)
83  except:
84  sys.stderr.write(
85  "Failed to deregister custom file resolver: %s\n" %
86  adskFileSchemeResolver.kPluginResolverName)
87  raise
88 
89 #-
90 # ==========================================================================
91 # Copyright (C) 2012 Autodesk, Inc. and/or its licensors. All
92 # rights reserved.
93 #
94 # The coded instructions, statements, computer programs, and/or related
95 # material (collectively the "Data") in these files contain unpublished
96 # information proprietary to Autodesk, Inc. ("Autodesk") and/or its
97 # licensors, which is protected by U.S. and Canadian federal copyright
98 # law and by international treaties.
99 #
100 # The Data is provided for use exclusively by You. You have the right
101 # to use, modify, and incorporate this Data into other products for
102 # purposes authorized by the Autodesk software license agreement,
103 # without fee.
104 #
105 # The copyright notices in the Software and this entire statement,
106 # including the above license grant, this restriction and the
107 # following disclaimer, must be included in all copies of the
108 # Software, in whole or in part, and all derivative works of
109 # the Software, unless such copies or derivative works are solely
110 # in the form of machine-executable object code generated by a
111 # source language processor.
112 #
113 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
114 # AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED
115 # WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF
116 # NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
117 # PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR
118 # TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS
119 # BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
120 # DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK
121 # AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY
122 # OR PROBABILITY OF SUCH DAMAGES.
123 #
124 # ==========================================================================
125 #+