scripted/whatIsCmd.py

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