scripted/pyHelloWorldCmd.py

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