Skip to content

Instantly share code, notes, and snippets.

@SEVEZ
Last active May 25, 2021 13:33
Show Gist options
  • Save SEVEZ/38c2926d2a94867e32e6 to your computer and use it in GitHub Desktop.
Save SEVEZ/38c2926d2a94867e32e6 to your computer and use it in GitHub Desktop.
# WORKS ONLY IN LEGACY VIEWPORT
import maya.OpenMaya as om
import maya.OpenMayaMPx as mpx
import sys
kPluginCtxName = 'myContext'
kPluginCmdName = 'myContextCmd'
class context(mpx.MPxContext):
def __init__(self):
mpx.MPxContext.__init__(self)
def doPress(self, event):
sys.stderr.write('It works I hope!!!!!')
class contextCommand(mpx.MPxContextCommand):
def __init__(self):
mpx.MPxContextCommand.__init__(self)
def makeObj(self):
return mpx.asMPxPtr(context())
@classmethod
def creator(cls):
return mpx.asMPxPtr(cls())
def initializePlugin(mobject):
mplugin = mpx.MFnPlugin(mobject, "Passerby", "1.0", "Any")
try:
mplugin.registerContextCommand(kPluginCtxName, contextCommand.creator)
except:
sys.stderr.write("Failed to register context command: %s\n" % kPluginCtxName)
raise
# Uninitialize the script plug-in
def uninitializePlugin(mobject):
mplugin = mpx.MFnPlugin(mobject)
try:
mplugin.deregisterContextCommand(kPluginCtxName, kPluginCmdName)
except:
sys.stderr.write("Failed to deregister context command: %s\n" % kPluginCtxName)
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment