View Full Version : Popup menu in a custom context

04 April 2009, 02:58 PM

I'm writing a custom selection context using MPxContext. I want to implement an object pick chooser pop-up menu similar to the one in Maya's selection tool (Can be turned on in the selection preferences). Like the one built-in, I want it to be triggered by the left mouse button. So when I click it runs my onPress function and then pops up a menu based on the result.

I have been trying to use a popup menu for this, but it won't work because the popup is being triggered first, and so my onpress function does not get executed. The only way I can think of is to draw my own menu in openGL/glut. I don't have much experience with either. So I don't know whether this is a viable option. Any thoughts?


04 April 2009, 10:30 PM
Hi Andy,

don't know if this is useful... however will suggest you to take a look at this post "adding items to an objects RMB menu (" by macaroniKazoo... :)

kind regards


04 April 2009, 10:45 PM
did you try your function in popUpMenu's -postMenuCommand?

"dagObjectHit"isn't in the mel command documentation however you can find all the flags for it in quick help.

additionally ls -preSelectHilite

is helpful for contextual component cursor query
a template fer both:

// cly_contextualCursorHit_template.mel
//__________________________________________________ ______________________________________
if( `popupMenu -exists cly_contextualTrash` ) {
deleteUI cly_contextualTrash;
-alt 1
-button 3
-mm 1
-p viewPanes
-pmc ( "string $bob[] = `ls -preSelectHilite`;"+ // ls return of pre-select hilite under cursor
"if (`popupMenu -e -exists cly_contextualTrash`) {"+
"popupMenu -e -deleteAllItems cly_contextualTrash;"+
" setParent -menu cly_contextualTrash;"+
"if ( `dagObjectHit`)"+ // dag object Hit returns int if cursor is over an object
"menuItem -label \"object under cursor\";"+
" menuItem -label \"no object under cursor\";"+
"if ( size( $bob ) ) "+
" for ( $b in $bob ) "+
"-label $b; }" )
//__________________________________________________ ______________________________________
// end

after executing the above code:
alt + rightclick on object and components
builds dynamic popUp that reflects object and component status under cursor

04 April 2009, 03:33 PM
Thanks for the replies.

Alex - Yes I know about the dagMenuProc techinique, but that's not what I am after.

Claydough - I had not heard of the dagObjectHit command before. I think that could become useful for part of my context. That's strange that it has never been documented.

I think I can hack something together by putting the content of my onPress function in the context into a command. Then defining the popmenu instead, and use the postMenuCommand to execute my command. The only downside being that I want the popup menu conditionally driven only if there is more than one object to select. Plus I don't need to handle components.

Its given me a few ideas. So thanks.

CGTalk Moderation
04 April 2009, 03:33 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.