Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Maya (2023) crashes when tuple supplied as flag to command in python api 2

Maya (2023) crashes when tuple supplied as flag to command in python api 2

houghton07
Explorer Explorer
293 Views
0 Replies
Message 1 of 1

Maya (2023) crashes when tuple supplied as flag to command in python api 2

houghton07
Explorer
Explorer

Hi,

 

I found this documentation for supplying a tuple as a flag to a custom command in api 1 and I'm tried conver...

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

294 Views
0 Replies
Replies (0)