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