Getting command arguments for a custom command

16 views
Skip to first unread message

Russel Rehmund

unread,
Jun 15, 2019, 4:52:28 PM6/15/19
to Python Programming for Autodesk Maya
Hi there,

I'm trying to write a command plugin for maya, which I'd like to give a list of assets from the scene:

cmds.ls(selection=True)


I'd like to then accept this list into my command either as an argument or give it to a flag, but this is where my knowledge stops.  I'd like to be able to do one of the following:

(As an argument)
assets = cmds.ls(selection=True)
cmds.my_command(assets, some_flags=True)

(To a flag)
assets = cmds.ls(selection=True)
cmds.my_command(asset_flag=assets, some_flags=True)


My first attempt was trying to use a flag, but getting a list from a flag wasn't trivial, so I'm now trying to get it as an argument using:

arg_parser_data = om.MArgParser(self.syntax(), args)

assets = om.MSelectionList()
success = arg_parser_data.getObjects(assets)

However I keep getting an unhelpful "Internal Failure Error" from maya.  Any help or indications would be great!

Thanks,

Russ

Justin Israel

unread,
Jun 15, 2019, 8:18:51 PM6/15/19
to python_in...@googlegroups.com
If you want to make it work like many of the existing Maya commands that take either objects as arguments, or falls back to the selection list, then you likely want to look at using MSyntax with an object list, and MArgDatabase:

This would hand you the selection automatically. 


Thanks,

Russ

--
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/3df69889-f6d6-4164-b01f-7c1b0b0ecf46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Russel Rehmund

unread,
Jun 16, 2019, 12:58:49 AM6/16/19
to Python Programming for Autodesk Maya
So to be clear, I should be using the parser and the database classes?  If I try the following, I still get an internal error:

arg_data = om.MArgDatabase(self.syntax(), args)

assets = om.MSelectionList()
success = arg_data.getObjects(assets)


When it comes to getting the values of specific flags, I've got the value with help from examples, doing this:

        if arg_data.isFlagSet(kShortCamName):
            # We use the '0' to index the flag's first and only parameter.
            cam_name = arg_data.flagArgumentString(kShortCamName, 0)

But when I try similarly to use arg_data.commandArgumentString(0), I get an error.  I've gone and done the follow syntax command also:

syntax = om.MSyntax()
syntax.setObjectType(om.MSyntax.kStringObjects, 1)

Is there no way for me to get the list of strings passed to my command?  This problem got me stumped.


On Saturday, 15 June 2019 20:18:51 UTC-4, Justin Israel wrote:


On Sun, Jun 16, 2019, 8:52 AM Russel Rehmund <russel...@gmail.com> wrote:
Hi there,

I'm trying to write a command plugin for maya, which I'd like to give a list of assets from the scene:

cmds.ls(selection=True)


I'd like to then accept this list into my command either as an argument or give it to a flag, but this is where my knowledge stops.  I'd like to be able to do one of the following:

(As an argument)
assets = cmds.ls(selection=True)
cmds.my_command(assets, some_flags=True)

(To a flag)
assets = cmds.ls(selection=True)
cmds.my_command(asset_flag=assets, some_flags=True)


My first attempt was trying to use a flag, but getting a list from a flag wasn't trivial, so I'm now trying to get it as an argument using:

arg_parser_data = om.MArgParser(self.syntax(), args)

assets = om.MSelectionList()
success = arg_parser_data.getObjects(assets)

However I keep getting an unhelpful "Internal Failure Error" from maya.  Any help or indications would be great!

If you want to make it work like many of the existing Maya commands that take either objects as arguments, or falls back to the selection list, then you likely want to look at using MSyntax with an object list, and MArgDatabase:

This would hand you the selection automatically. 


Thanks,

Russ

--
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_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages