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