Skip to content

Instantly share code, notes, and snippets.

@ourway
Created March 7, 2015 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ourway/b0041657e7fd708203c7 to your computer and use it in GitHub Desktop.
Save ourway/b0041657e7fd708203c7 to your computer and use it in GitHub Desktop.
Maya scripted command plug-in
import sys
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
kPluginCmdName = "spHelloWorld"
# Command
class scriptedCommand(OpenMayaMPx.MPxCommand):
def __init__(self):
OpenMayaMPx.MPxCommand.__init__(self)
# Invoked when the command is run.
def doIt(self,argList):
print "Hello World!"
# Creator
def cmdCreator():
return OpenMayaMPx.asMPxPtr( scriptedCommand() )
# Initialize the script plug-in
def initializePlugin(mobject):
mplugin = OpenMayaMPx.MFnPlugin(mobject)
try:
mplugin.registerCommand( kPluginCmdName, cmdCreator )
except:
sys.stderr.write( "Failed to register command: %s\n" % kPluginCmdName )
raise
# Uninitialize the script plug-in
def uninitializePlugin(mobject):
mplugin = OpenMayaMPx.MFnPlugin(mobject)
try:
mplugin.deregisterCommand( kPluginCmdName )
except:
sys.stderr.write( "Failed to unregister command: %s\n" % kPluginCmdName )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment