Outline Editor Contextual Menu On Custom Node

Outline Editor Contextual Menu On Custom Node

Philipp99_N
Community Visitor Community Visitor
1,131 Views
2 Replies
Message 1 of 3

Outline Editor Contextual Menu On Custom Node

Philipp99_N
Community Visitor
Community Visitor

Hello,
I have created a custom node based on an OpenMayaMPx.MPxLocatorNode. The node is created and registered in Python (I used this example as a starting point: https://help.autodesk.com/view/MAYAUL/2023/ENU/?guid=MAYA_API_REF_py_ref_python_2api1_2py1_rocking_t...). So far it works, and when I add the node to the scene, it appears in the outline editor as expected. I now want to add some menu items to the context menu that appears when a node is hovered and right-clicked in the outline editor. I want these menu items to perform custom actions for the selected node and be visible only on nodes of that custom type. I have not yet found a solution that works for this case. Can anyone help me with this issue?

0 Likes
1,132 Views
2 Replies
Replies (2)
Message 2 of 3

FirespriteNate
Advocate
Advocate

The only way (afaik) to custom modify the Outliner RMB-popup menu is to provide a MEL script named:

outlinerEdMenuUserCallback.mel

This is sourced (reloaded and executed) automatically every time you right-click in the outliner.

 

For example, save this code into a file with the exact name above, and save it into your documents\maya\scripts\ folder (or somewhere on your Maya scripts path):

 

menuItem -sm 1 -l "My Custom SubMenu";
	menuItem -l "do something";
setParent -m "..";

 

(you'll need to restart Maya or "rehash"). But now, when you do, right clicking in the Outliner should show something like this:

FirespriteNate_0-1690536127552.png

 

However, this MEL callback doesn't provide any arguments, so you have no idea what the user clicked on, so the only thing you can query/rely on is what is currently selected. If, for example you wanted this menu to only appear when you had a specific node type selected, you'd have to check and handle that yourself.

Also, if you're working in Python, you probably don't want to do this in MEL, so you might want to write your custom menu functionality in python and just use outlinerEdMenuUserCallback.mel to call your Python code.

 

If you wanted to insert your new custom menu somewhere else in the outliner popup (i.e. not at the bottom) you will need to know the names of the other menu items in it, which you can find out by browsing the MEL file that creates it: OutlinerEdMenu.mel

 

I hope this is enough to get you started.

Message 3 of 3

joeleveson
Explorer
Explorer

I've found the only way is to adda callback:

def myCallbackFunction(arg1):
    cmds.menuItem(divider=True, insertAfter="")
    cmds.menuItem("myCallbackFunction", enableCommandRepeat=False, label="My Command", command="cmds.polySphere()")

cmds.callbacks(addCallback=myCallbackFunction, hook='addItemsToOutlinerNodePopupMenu', owner='myPlugin')

 

0 Likes