Share

Hello World source code for Python API 1.0

import sys
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx

# command
class Py1HelloWorldCmd(OpenMayaMPx.MPxCommand):
    kPluginCmdName = "py1HelloWorld"

    def __init__(self):
        OpenMayaMPx.MPxCommand.__init__(self)

    @staticmethod
    def cmdCreator():
        return OpenMayaMPx.asMPxPtr( Py1HelloWorldCmd() )

        def doIt(self,argList):
            print ("Hello World!")

# Initialize the script plug-in
def initializePlugin(plugin):
    pluginFn = OpenMayaMPx.MFnPlugin(plugin)
    try:
        pluginFn.registerCommand(
        Py1HelloWorldCmd.kPluginCmdName, Py1HelloWorldCmd.cmdCreator
    )
    except:
        sys.stderr.write(
            "Failed to register command: %s\n" % Py1HelloWorldCmd.kPluginCmdName
    )
    raise

# Uninitialize the script plug-in
def uninitializePlugin(plugin):
    pluginFn = OpenMayaMPx.MFnPlugin(plugin)
    try:
        pluginFn.deregisterCommand(Py1HelloWorldCmd.kPluginCmdName)
    except:
        sys.stderr.write(
            "Failed to unregister command: %s\n" % Py1HelloWorldCmd.kPluginCmdName
        )
    raise

Was this information helpful?