Returning a string from a command plugin?

58 views
Skip to first unread message

Russel Rehmund

unread,
Jun 20, 2019, 12:11:06 PM6/20/19
to Python Programming for Autodesk Maya
Anyone know how to properly work this?  Any examples or links to documentation would be appreciated.

I'm trying to return a string from my command plugin, though I'm not even sure it's possible.  The string is the name of a camera that I've created.

I'd like to be able to do this:

camera = cmds.my_command()


Here's my initialize function:

def initializePlugin(mobject):
    mplugin = omMPx.MFnPlugin(mobject, author, version, 'Any')
    try:
        cam = mplugin.registerCommand(kPluginCmdName, cmdCreator, syntaxCreator)
        log.info("Successfully registered plugin: {0}".format(kPluginCmdName))
        if cam:
            return cam
    except Exception as e:
        log.critical("Failed to register command: {0}".format(kPluginCmdName))
        log.critical(traceback.format_exc(e))
        raise

My doIt function:

    def doIt(self, args):
        """ Command execution. """
        arg_data = om.MArgDatabase(self.syntax(), args)
      
       ... flags parsing

        # Run the turntable code here.
        cam = main(...)
        return cam

Am I missing something here?

Ian Jones

unread,
Jun 20, 2019, 12:16:47 PM6/20/19
to Python Programming for Autodesk Maya
Believe you are looking for self.setResult(cam)

Set the value of the result to be returned by the command.
Name:setResult(value)
Parameters:value - bool, int, float, string, sequence of numerics or sequence of strings
Returns:None
Description:Set the value of the result to be returned by the command.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/da684b50-5c6d-425c-a87b-e9f902ec0414%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Russel Rehmund

unread,
Jun 20, 2019, 12:22:36 PM6/20/19
to Python Programming for Autodesk Maya
Thank you!


On Thursday, 20 June 2019 12:16:47 UTC-4, Ian Jones wrote:
Believe you are looking for self.setResult(cam)

Set the value of the result to be returned by the command.
Name:setResult(value)
Parameters:value - bool, int, float, string, sequence of numerics or sequence of strings
Returns:None
Description:Set the value of the result to be returned by the command.

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Eugene Lominin

unread,
Feb 24, 2023, 9:31:54 AM2/24/23
to Python Programming for Autodesk Maya

In Maya API 2.0  setResult() always returns a list to caller.

In python command I have self.setResult(0.5)
Then I call from mel script  I receive [0.5] 

$res=`getCustomPaintValue -1 4522`;
print("------- getCustomPaintValue1: " + $res + "\n");
I console I have error:
// Error: print("------- getCustomPaintValue1: " + $res + "\n");
// Error: Line 2.47: Illegal operation "+" on data of type float[].

I can use $res[0] in this command, but it doesn't work for other calls.
How can I return command result as float not a list?
Thanks.
Reply all
Reply to author
Forward
0 new messages