View Full Version : Parsing mel commands in Python using API?

10 October 2011, 01:32 PM
From the documentation it seems that it is not possible to use API classes to parse mel commands outside MPxCommand. I want to parse some mel commands for analysis purpose using API functions in python. Is it possible to use MArgParser and sepcifically MArgList outside command nodes?
It seems I cannot create MArgList object manually right?

10 October 2011, 01:36 PM
Did you actually read the documentation? MArgList is not available in python but MArgParser should work fine. The syntax of the functions is a little different tho.

Do not use MArgList to parse flags for a plug-in command as the flags will not work if the command is called from Python. Use MArgParser or MArgDatabase instead.

10 October 2011, 02:41 PM
I am not creating a command using MPxCommand like I mentioned in my original post. I am looking at the possibilities of using API functions to parse some mel commands in a python script. And there is no way to build MArgList ourselves and MArgParser needs MArgList as a parameter to initialize the object. I cannot see any way to use MArgParser independently!

10 October 2011, 03:12 PM
Don't get exactly what you are trying to do but if you are just trying to parse arguments out from a string that maybe is "melCommand -f file -t somethingelse -t blub" I would just use regular python.

10 October 2011, 03:49 PM
Yes I want to parse mel commands from string like your example. I am using python right now, but I was wondering if anything from python API could be useful in speeding up the parsing.

11 November 2011, 01:36 AM
I peeked at the doc, and it doesn't look like you can init these classes manually. Maybe you could try executing a script with the string you are trying to parse as a command line params, and maybe inside this script the MArgList would be available. But I'm not sure why you bother, IMO python's parser or even a simple regex could do the job more easily.

11 November 2011, 03:19 PM
Yeah that's what I thought, but I was wondering if I was missing anything in API documentation.

The problem is not so much of separating elements, but to find what are the values assigned to flags and what are the objects and not string values, also many flags have multiple arguments possible. And on top of that you can write commands this way,

setAttr -c-l on nurbsCircle1.t-.3-.1-.3

While not very difficult, this is not straightforward to generalize. That's why I wanted to see if I could use API. Right now I am just doing the same thing as API using plain python, specify syntax and then parse.

CGTalk Moderation
11 November 2011, 03:19 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.