Python examples of custom contexts

81 views
Skip to first unread message

Andruha Prostrelov

unread,
Aug 13, 2014, 12:30:08 AM8/13/14
to python_in...@googlegroups.com
Can some one share examples of custom context tool realisation via python ?
There are a lot of examples on C++ in books and documentation.
But no python scripts. The python scripts i googled are more like a dummy.

Here is a dummy script:
import maya.cmds as cmds
import maya.OpenMaya as om
import maya.OpenMayaMPx as mpx
import sys

pluginCtxName
= "CustomContext"

class CustomSelectContext(mpx.MPxSelectionContext):
   
def __init__(self):
        mpx
.MPxSelectionContext.__init__(self)
   
   
def doPress(self, event):
       
print ('SHLOOOOOOOOOOOOOOOOMP')
       
class CommandCreator(mpx.MPxContextCommand):
   
def __init__(self):
        mpx
.MPxContextCommand.__init__(self)
   
   
def makeObj(self):
       
return mpx.asMPxPtr(CustomSelectContext())    


def initializePlugin(mobject):
    mplugin
= mpx.MFnPlugin(mobject)
   
try:
        mplugin
.registerContextCommand( pluginCtxName, CommandCreator )  
   
except:
       
print "Failed to register context command: %s" % pluginCtxName
       
raise


def uninitializePlugin(mobject):
    mplugin
= mpx.MFnPlugin(mobject)
   
try:
        mplugin
.deregisterContextCommand(pluginCtxName)
   
except:
       
print "Failed to deregister context command: %s" % pluginCtxName
       
raise

I am looking for something more complex.

Reply all
Reply to author
Forward
0 new messages