scripted/pyHelloWorldCmd.py

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