Lala_Ghost
Lala_Ghost

Reputation: 211

How to run function objects(Maya, Python)?

Sometimes when I query a command of a button or something like that I get this:

For example:

cmds.menuItem('MtoAReleaseNotes', query = True, command = True)

>>> <function <lambda> at 0x0000019849774588>

So how do I run these commands via Python?

Upvotes: 0

Views: 672

Answers (1)

haggi krey
haggi krey

Reputation: 1978

Something like this:

<function callback at 0x0000021B812B24A8>

Is a function object like this one:

def hello():
    print "Hello"

f = hello

Now f contains the function object for hello:

<function hello at 0x0000019493BCE7B8> 

And it can be executed by using "()" so try this:

f()

The result should be "Hello". Corresponding to your updated question this should work:

f = cmds.menuItem(x, query = True, command = True)

and to run the command:

f()

Upvotes: 3

Related Questions