Search code examples
pythonpython-3.xmayaautodeskmel

How to invoke/execute Maya menu item using Python?


I would like to learn how to invoke/trigger a menu bar item in Maya using python.

For example, opening the "content browser" dialog window from menu bar:Windows->General Editors->Content Browser.

Appreciate any hints on this! Thank you!


Solution

  • If you enable "Echo all commands" in the script editor, you can see which commands are executed if you choose a menu item, in this case it is:

    OpenContentBrowser;
    

    So from python you can try it with pymel:

    import pymel.core as pm
    pm.mel.OpenContentBrowser()
    

    Or with cmds:

    import maya.cmds as cmds
    cmds.OpenContentBrowser()