scripted/pyWhatIsCmd.py

scripted/pyWhatIsCmd.py
1 """
2 To use, make sure that pyWhatIsCmd.py is in your MAYA_PLUG_IN_PATH
3 then do the following:
4 
5 import maya.cmds
6 maya.cmds.loadPlugin("pyWhatIsCmd.py")
7 maya.cmds.pyWhatIs()
8 """
9 
10 import sys
11 import maya.api.OpenMaya as om
12 
13 def maya_useNewAPI():
14  """
15  The presence of this function tells Maya that the plugin produces, and
16  expects to be passed, objects created using the Maya Python API 2.0.
17  """
18  pass
19 
20 
21 # command
22 class PyWhatIsCmd(om.MPxCommand):
23  kPluginCmdName = "pyWhatIs"
24 
25  def __init__(self):
26  om.MPxCommand.__init__(self)
27 
28  @staticmethod
29  def cmdCreator():
30  return PyWhatIsCmd()
31 
32  def doIt(self, args):
33  selectList = om.MGlobal.getActiveSelectionList()
34  depFn = om.MFnDependencyNode()
35 
36  for i in range(selectList.length()):
37  node = selectList.getDependNode(i)
38 
39  depFn.setObject(node)
40 
41  types = om.MGlobal.getFunctionSetList(node)
42 
43  print "Name: %s" % depFn.name()
44  print "Type: %s" % node.apiTypeStr
45  sys.stdout.write( "Function Sets: " )
46  sys.stdout.write(", ".join(types) + '\n')
47 
48 
49 # Initialize the script plug-in
50 def initializePlugin(plugin):
51  pluginFn = om.MFnPlugin(plugin)
52  try:
53  pluginFn.registerCommand(
54  PyWhatIsCmd.kPluginCmdName, PyWhatIsCmd.cmdCreator
55  )
56  except:
57  sys.stderr.write(
58  "Failed to register command: %s\n" % PyWhatIsCmd.kPluginCmdName
59  )
60  raise
61 
62 # Uninitialize the script plug-in
63 def uninitializePlugin(plugin):
64  pluginFn = om.MFnPlugin(plugin)
65  try:
66  pluginFn.deregisterCommand(PyWhatIsCmd.kPluginCmdName)
67  except:
68  sys.stderr.write(
69  "Failed to unregister command: %s\n" % PyWhatIsCmd.kPluginCmdName
70  )
71  raise
72 
73 #-
74 # ==========================================================================
75 # Copyright (C) 2011 Autodesk, Inc. and/or its licensors. All
76 # rights reserved.
77 #
78 # The coded instructions, statements, computer programs, and/or related
79 # material (collectively the "Data") in these files contain unpublished
80 # information proprietary to Autodesk, Inc. ("Autodesk") and/or its
81 # licensors, which is protected by U.S. and Canadian federal copyright
82 # law and by international treaties.
83 #
84 # The Data is provided for use exclusively by You. You have the right
85 # to use, modify, and incorporate this Data into other products for
86 # purposes authorized by the Autodesk software license agreement,
87 # without fee.
88 #
89 # The copyright notices in the Software and this entire statement,
90 # including the above license grant, this restriction and the
91 # following disclaimer, must be included in all copies of the
92 # Software, in whole or in part, and all derivative works of
93 # the Software, unless such copies or derivative works are solely
94 # in the form of machine-executable object code generated by a
95 # source language processor.
96 #
97 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
98 # AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED
99 # WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF
100 # NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
101 # PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR
102 # TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS
103 # BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
104 # DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK
105 # AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY
106 # OR PROBABILITY OF SUCH DAMAGES.
107 #
108 # ==========================================================================
109 #+