scripted/helloWorldCmd.py

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