Thursday, April 18, 2013
My own "Hello, World!" Maya plug-in
Yestarday, I used Maya devkit example to learn Maya plug-ins. Today, I will create my own alternative Hello World plug-in!
import maya.OpenMaya as om
import maya.OpenMayaMPx as ommpx
class AR_HelloWorldCmd(ommpx.MPxCommand):
"""
A command that prints a string to the console.
"""
## the name of the command
kPluginCmdName = 'ar_helloWorld'
def __init__(self):
"""
Initialize the instance.
"""
ommpx.MPxCommand.__init__(self)
def doIt(self, args):
"""
Print string to the console.
"""
print('Hello, world!')
@classmethod
def cmdCreator(cls):
"""
Return pointer to proxy object.It has to always call this method when creating MPx objects in scripted plug-ins.
"""
return ommpx.asMPxPtr(cls())
def initializePlugin(obj):
"""
Initialize the plug-in.
"""
plugin = ommpx.MFnPlugin(
obj,
'Meng',
'1.0',
'Any'
)
try:
plugin.registerCommand(
AR_HelloWorldCmd.kPluginCmdName,
AR_HelloWorldCmd.cmdCreator
)
except:
raise Exception(
'Failed to register command: %s'%
AR_HelloWorldCmd.kPluginCmdName
)
def uninitializePlugin(obj):
"""
Uninitialize the plug-in.
"""
plugin = ommpx.MFnPlugin(obj)
try:
plugin.deregisterCommand(AR_HelloWorldCmd.kPluginCmdName)
except:
raise Exception(
'Failed to unregister command: %s'%
AR_HelloWorldCmd.kPluginCmdName
)
It is critical to note again that you must unload and then reload a plug-in to see changes that you are making in an external text editor become active in Maya.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment