Message 1 of 9
Python api 2.0 - Cannot initialize plugin with MPxToolCommand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone. I was wondering if anyone else has managed to successfully initialize a custom context plugin that uses MPxToolCommand in python api 2? Maybe I'm doing something wrong.
In the registerContextCommand function, I've passed the arguments in this order:
context command name string
context command creator function
tool command name string
tool command creator function
tool command syntax function
If i remove the tool command arguments, it initializes. It also fails if I remove just the syntax function. If i change it over to API 1, it initializes.
Any thoughts? Thanks.
BTW, I've pasted the code here. It's just a test plugin with no functionality:
import maya.api.OpenMaya as om
import maya.api.OpenMayaUI as omui
import maya.cmds as cmds
def maya_useNewAPI():
pass
class TestingContext(omui.MPxContext):
TITLE = "TEST TOOL"
def __init__(self):
super(TestingContext, self).__init__()
def helpStateHasChanged(self, event):
self.setHelpString("Help test")
def toolOnSetup(self, event):
print("TOOL SET UP")
def doPress(self, event, draw_manager, frame_context):
print("PRESSED")
def doDrag(self, event, draw_manager, frame_context):
print("---")
def doRelease(self, event, draw_manager, frame_context):
print("RELEASED")
class TestingContextCmd(omui.MPxContextCommand):
COMMAND_NAME = "testingCtx"
def __init__(self):
super(TestingContextCmd, self).__init__()
def makeObj(self):
return TestingContext()
@classmethod
def creator(cls):
return TestingContextCmd()
class TestingContextToolCmd(omui.MPxToolCommand):
COMMAND_NAME = "testingToolCmd"
def __init__(self):
super(TestingContextToolCmd, self).__init__()
self.commandString = self.COMMAND_NAME
self.undoable = False
def doIt(self, arg_list):
pass
def undoIt(self):
pass
def redoIt(self):
pass
def isUndoable(self):
return self.undoable
def doFinalize(self):
pass
@classmethod
def creator(cls):
return TestingContextToolCmd()
@classmethod
def create_syntax(cls):
syntax = om.MSyntax()
return syntax
def initializePlugin(plugin):
vendor = "me"
version = "1.0"
plugin_fn = om.MFnPlugin(plugin, vendor, version)
try:
plugin_fn.registerContextCommand(TestingContextCmd.COMMAND_NAME, TestingContextCmd.creator,
TestingContextToolCmd.COMMAND_NAME, TestingContextToolCmd.creator,
TestingContextToolCmd.create_syntax)
except:
om.MGlobal.displayError("Failed to register context command: {0}".format(TestingContextCmd.COMMAND_NAME))
def uninitializePlugin(plugin):
plugin_fn = om.MFnPlugin(plugin)
try:
plugin_fn.deregisterContextCommand(TestingContextCmd.COMMAND_NAME, TestingContextToolCmd.COMMAND_NAME)
except:
om.MGlobal.displayError("Failed to deregister context command: {0}".format(TestingContextCmd.COMMAND_NAME))