Need help with a Python Command Plugin - Parsing Arguments

I am hitting a strange internal error with a custom command plugin written in python:


RuntimeError: file c:\builds\maya-2014-w64\build\Release\runTime\Python\Lib\site-packages\maya\OpenMaya.py line 1685: (kFailure): Unexpected Internal Failure # 

my command can grab the selection list, but it can also be passed strings and lists of nodes. I am hitting the problem above when a node that doesn’t exist is passed to the command as an argument.

I expected to get:

# Error: ValueError: No object matches name: IDontExist #

which is what happens in some of our other command plugins that are written in C++.

Here is a snippet of code:

    
    @staticmethod
    def syntaxCreator():
        syntax = om.MSyntax()
        syntax.addFlag(MyCmd.ARG_TYPE, MyCmd.ARG_TYPE_LONG, om.MSyntax.kString) # string or list
        syntax.addFlag(MyCmd.ARG_ALL, MyCmd.ARG_ALL_LONG) # bool
        syntax.makeFlagMultiUse(MyCmd.ARG_TYPE)
        syntax.useSelectionAsDefault(True) 
        syntax.setObjectType(om.MSyntax.kSelectionList) 
        return syntax


    def parseArgs(self, args):
        try:
            argData = om.MArgDatabase(self.syntax(), args) # this is where the internal error occurs
        except RuntimeError:
            om.MGlobal.displayError('Error while parsing arguments.')
            raise

Is there anything special I need to do to validate the nodes passed into the command to verify they exist?

It looks like this may be a bug in the Python version of the API. I tried running one of Autodesk’s example commands from the devkit, pyMetaDataCmd.py. I tried running it with a non existent object name:

cmds.pyMetaData('cookies')

The error showed up as “Unexpected Internal Failure”, like you got.

cmds.pyMetaData('cookies')
# Error: Error while parsing arguments:
# #	# If passing in list of nodes, also check that node names exist in scene.
# (kFailure): Unexpected Internal Failure
# # Traceback (most recent call last):
# #   File "C:/Users/rflannery/Documents/maya/2013.5-x64/plug-ins/pyMetaDataCmd.py", line 115, in doIt
# #     argdb = om.MArgDatabase(self.syntax(), args)
# # RuntimeError: (kFailure): Unexpected Internal Failure
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
#   File "<string>", line 2, in pyMetaData
# RuntimeError: Error while parsing arguments:
# #	# If passing in list of nodes, also check that node names exist in scene.
# (kFailure): Unexpected Internal Failure
# # Traceback (most recent call last):
# #   File "C:/Users/rflannery/Documents/maya/2013.5-x64/plug-ins/pyMetaDataCmd.py", line 115, in doIt
# #     argdb = om.MArgDatabase(self.syntax(), args)
# # RuntimeError: (kFailure): Unexpected Internal Failure # 

Interesting snippet of code from the plugin:

        try:
            argdb = om.MArgDatabase(self.syntax(), args)
        except RuntimeError:
            om.MGlobal.displayError('Error while parsing arguments:
#	# If passing in list of nodes, also check that node names exist in scene.')
            raise

The error message makes me think whoever wrote this example plugin must know that passing invalid node names causes this error.