Hi,
I found this documentation for supplying a tuple as a flag to a custom command in api 1 and I’m tried convert it to api 2 but it crashes when I call the command. Here is my code
import sys
import maya.api.OpenMaya as om
def maya_useNewAPI():
"""
The presence of this function tells Maya that the plugin produces, and
expects to be passed, objects created using the Maya Python API 2.0.
"""
pass
kShortFlagName = '-tf'
kLongFlagName = '-myTupleFlag'
class MyCommandWithFlagClass(om.MPxCommand):
kPluginCmdName = 'myCommandWithFlag'
def __init__(self):
super(MyCommandWithFlagClass, self).__init__()
def doIt(self, args):
self.parseArguments(args)
def parseArguments(self, args):
argData = om.MArgParser(self.syntax(), args)
if argData.isFlagSet(kShortFlagName):
flagParam0 = argData.flagArgumentInt(kShortFlagName, 0)
flagParam1 = argData.flagArgumentInt(kShortFlagName, 1)
flagParam2 = argData.flagArgumentInt(kShortFlagName, 2)
print(kLongFlagName + '[0]: ' + str(flagParam0))
print(kLongFlagName + '[1]: ' + str(flagParam1))
print(kLongFlagName + '[2]: ' + str(flagParam2))
@staticmethod
def cmdCreator():
return MyCommandWithFlagClass()
@staticmethod
def syntaxCreator():
syntax = om.MSyntax()
syntax.addFlag(kShortFlagName, kLongFlagName, om.MSyntax.kDouble, om.MSyntax.kDouble, om.MSyntax.kDouble)
return syntax
# Initialize the plug-in
def initializePlugin(plugin):
pluginFn = om.MFnPlugin(plugin)
try:
pluginFn.registerCommand(
MyCommandWithFlagClass.kPluginCmdName, MyCommandWithFlagClass.cmdCreator, MyCommandWithFlagClass.syntaxCreator
)
except:
sys.stderr.write(
"Failed to register command: %s\n" % MyCommandWithFlagClass.kPluginCmdName
)
# Uninitialize the plug-in
def uninitializePlugin(plugin):
pluginFn = om.MFnPlugin(plugin)
try:
pluginFn.deregisterCommand(MyCommandWithFlagClass.kPluginCmdName)
except:
sys.stderr.write(
"Failed to unregister command: %s\n" % MyCommandWithFlagClass.kPluginCmdName
)
I took line 46 (and the rest of the contents of the syntaxCreator method) directly from the documentation so I’m not sure why it’s crashing. Any help would be greatly appreciated!
Thanks,
-Harry