On Thu, Mar 26, 2009 at 02:24, King <[email protected]> wrote:
>
> I have created a MPxCommand without MSyntax. Arguments are parsed by
> loop method and *help* is available when "-h" or "-help" flag is
> passed. Mel syntax is:
>
> itemFilterAttribute -at "_vpr_animatedVisibility" -ex 0 -v 1 -items
> $obj;
>
> Python is giving me an error:
>
> Error Parsing: Flag 'at' does not appear in help for command
> itemFilterAttribute. Skipping command formatting
> items=util.defaultlist(str, itemFilterAttribute
> ("_vpr_animatedVisibility", -ex, 0, -v, 1, -items, obj) # <----
> Formatting this command failed. You will have to fix this by hand)
>
> What's wrong here? and what's the solution?
>
> Is it because of MSyntax?

It's because of the lack of an MSyntax, yes.

It looks like you are using pymel syntax to call the command. pymel
uses Maya's 'help' command to determine which flags the command
supports and the 'help' command requires an MSyntax to know which
flags the command supports.

You can call the command directly, without going through pymel as follows:

    import maya.cmds as cmds
    result = cmds.itemFilterAttribute(at="_vpr_animatedVisibility",
ex=0, v=1, items=obj)

You shouldn't get the error message that way, however you'll find that
your command still doesn't work because the MArgList which is passed
to it won't contain any flags or flag arguments.

The reason for this is as follows. Let's say that you have a command
which takes an '-exists' flag. There are two ways in which you could
write your command. In one version, the flag takes a true/false
argument. E.g:

    mycmd -exists true something;

or you could write it such that the flag doesn't take an argument, in
which case the mere presence of '-exists' means to do an existence
check:

    mycmd -exists something;

In Python, both of those approaches would be called in exactly the same way:

    cmds.mycmd(exists=True)

Without an MSyntax object Maya has no way of knowing whether it should
put both '-exists' and 'True' into the MArgList, or just the
'-exists'.

There are other problems, too. For example, MArgList allows you to mix
command arguments and flags and their ordering will be preserved. E.g:

    mycmd obj1 obj2 -update off obj3 obj4 -update on obj5 obj6;

but Python insists that all non-flag arguments come before flags:

    cmds.mycmd(obj1, obj2, obj3, obj4, obj5, obj6, update=[False, True])

so you no longer know which of the objects came between the two 'update' flags.

For these reasons and more, if you want a command to work in Python
then you must do one of two things:

1) Only use command arguments, no flags.

or:

2) Provide an MSyntax description of your command's syntax and use
MArgParser or MArgDatabase to parse it.


-- 
-deane

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to