Last active
May 25, 2021 13:33
-
-
Save SEVEZ/38c2926d2a94867e32e6 to your computer and use it in GitHub Desktop.
From http://tech-artists.org/forum/showthread.php?4254-openMaya-contexts&highlight=MPxcontext
Open Maya custom context sample code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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