Search code examples
menumenuitemmayamel

how to add a menuitem in ModelPanel in Maya via mel scripting?


how to add a menuitem in ModelPanel ? yes! interesingly I couldnot find a proper way to add my menu in ModelPanel. (each of four top,front,persp,side)

eg. I wantto add my menu after "Look at Selection MenuItem"

is it possible ?

I found that $modelPanelShowMenus is a string array which is Menu of "Show" for all four viewPorts. but cant dive deeper.


Solution

  • Yes it is possible. You will need to override the function global proc postModelEditorViewMenuCmd which lives in file createModelPanelMenu.mel. Copy the entire procedure to a mel file to your user scripts folder. Do not change the original mel file!

    Then add your menu item definitions on the line that come after following line:

    $itemName = `menuItem -label (uiRes("m_createModelPanelMenu.kLookAtSelection"))
                -command ("{ string $camera = `modelEditor -q -camera "+$editor+"`;"+
                  "viewLookAt $camera;}")`;
    

    Then in your userSetup.mel call the mel file inside a eval deferred call to override the default behavior. And your set to go.

    Alternatively override the menu handler name in the panel itself. This allows you to chain the calls later.