Skip to content

Instantly share code, notes, and snippets.

@santosh
Created December 10, 2019 19:46
Show Gist options
  • Save santosh/3fb8e7d9d0ba234359046b6e6547311f to your computer and use it in GitHub Desktop.
Save santosh/3fb8e7d9d0ba234359046b6e6547311f to your computer and use it in GitHub Desktop.
Custom command inside maya. Similarly custom nodes can be created. Part of ADN.
import maya.OpenMayaMPx as ommpx
import sys
class Sample(ommpx.MPxCommand):
kPluginCmdName = "foo"
def __init__(self):
ommpx.MPxCommand.__init__(self)
@classmethod
def cmdCreator(cls):
return ommpx.asMPxPtr(cls())
def doIt(self, argList):
print("Hello World")
def initializePlugin(mobject):
mplugin = ommpx.MFnPlugin(mobject)
try:
mplugin.registerCommand(Sample.kPluginCmdName, Sample.cmdCreator)
except:
sys.stderr.write("Failed to register command: {}".format(Sample.kPluginCmdName))
raise
def uninitializePlugin(mobject):
mplugin = ommpx.MFnPlugin(mobject)
try:
mplugin.deregisterCommand(Sample.kPluginCmdName)
except:
sys.stderr.write(
"Failed to unregister command: {}".format(Sample.kPluginCmdName)
)
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment