PDA

View Full Version : right click dagMenuProc ??help please


skunk184
04-14-2009, 08:03 AM
I would like to add a marking menu to selected objects that contain a specific attribute. I also need the menu to be editable per object and i would like it to contain the old menu in a new submenu.

i ve looked at the 1800 plus lines of the dagMenuProc(pretty sure its where its at) and I can kinda see what its doing but dont really know where to start .

Im not a MEL newb but im no master either.

so any help would be very much appreciated and a step by step guide would be just great!

cheers

Craig

skunk184
04-14-2009, 05:44 PM
okay not too worry ... after a few hours of messing around and searching ...it looks like you only need to edit a line of code in the actual dagMenuProc and use an if else statement to execute a proc in a script node..

i may be wrong but it seems to work with my first test.


cheers

Craig

ewerybody
04-15-2009, 09:03 AM
I hacked my dagMenuProc for Maya7 as well. But I don't know if it works for 2009 still, didn't try yet.

I know its daaaarn huge. I needed some time as well.
So you want to modify the menu ONLY when you hit RMB on special attributed objects?

What did you change now?

skunk184
04-15-2009, 11:55 AM
i just added this line and all works fine ...i m guessing its not that different to 7 just 2009 has more options

if (`attributeExistis "attribute" $shortName` == 1)
{
//goto my scriptnode
procName $shortName ;
}else{

// do what you are supposed to do

}

the scriptNode has conditions to tell maya what menus to add and the objects to add them to.

cheers

Craig

claydough
04-15-2009, 01:09 PM
It's kind of drastic to edit Maya internal files.

cross posting this as dagMenuProc is coming up a lot lately...

some dagMenuProc notes:
( jes use an if condition for yer attribute in the final templates below )



from: http://forums.cgsociety.org/showthread.php?p=5810214#post5810214


More pop-up menu Fun...
different methods are needed to return "object under the cursor" depending on the panel.

First in the model panels:

How is the $object argument passed to dagMenuProc.mel ?!
This is a bit tricky!

The only procedure that uses dagMenuProc is buildObjectMenuItemsNow.mel.
And it only "seems" to execute it in only one place in the code...

if NOT! dagObjectHit -mn "theMenuNameHere" then the last object currently
selected is $object. So dagmenuProc ( in "theMenuNameHere", with
$object represented )

This works as expected ( if no cursor is over an object but at least 1 object is selected..
Then the last selected object is represented in the dagMenu pop up )
Where then, is dagMenuProc executed for cursor over unselected object?

ENTER, the enigmatic dark shadowy command known as dagObjectHit to save the day (sorta) once again...

although dagObjectHit only returns int. When used with an -menu flag
It executes dagMenuProc and passes as arguments both the menu string provided in
the flag and the object under the cursor as well!

for instance:

// with our cursor over polyMesh1...
dagObjectHit -mn "cly_contextualTrash", ;
// results in:
// dagMenuProc("cly_contextualTrash", "polyMesh1");


dagObjectHit is only used once in all internal Maya scripts...
( our buildObjectMenuItemsNow.mel example above)
if (!`dagObjectHit -mn $parentName`)
despite the logical !not operator this dagObjectHit query is what actually
executes cursor/object represented popUp menu builds.

Why this isn't a fully documented command that returns object query as a string is beyond me? May be some danger lurking here?

Let's not start celebrating jes yet tho..

For our uses, this code:

dagObjectHit -mn "ourCustomMenu"

will simply use the dagMenuProc menu builder to build "our" menu!
( the dagMenuBuild is appended to our menu so far )

Which is fine if that is what we want... ( to extend Maya's default model Menu Pop Ups )
However if we want unadultered popUpMenu's, yet keep the dagObjectHit's passed $object
We will have to do a little hacking:

Don't rewrite an internal mel file...
pillage dagMenuProc results instead, then -deleteAllItems to restore yer menu:

/*
cly_objectHitMenuTemplate.mel v0.2
Roger Klado was here
because no one else will do it fer me
April 15, 2009 ( should be dom war-ing instead )
RogerKlado@gmail.com ( Klado/Claydough/cly_ )
A template for setting up object aware view pane pop-up menus
*/
global proc cly_objectHitMenuTemplate()
{
if( `popupMenu -exists cly_contextualTrash` ) {
deleteUI cly_contextualTrash;
}
popupMenu
-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 `cly_dagMenuRape`;"+
"else"+
" menuItem -label \"no object under cursor\";"+
"if ( size( $bob ) ) "+
" for ( $b in $bob ) "+
"menuItem"+
"-label $b; }" )
cly_contextualTrash;
}
//________________________________________________________________________________________
// end
global proc string cly_dagMenuRape()
{
dagObjectHit -mn "cly_contextualTrash";
string $popsChildren[] = `popupMenu -q -itemArray cly_contextualTrash`;
string $objectMenuItem = `menuItem -q -l $popsChildren[0]`;
string $dotFreeObject[];
tokenize $objectMenuItem "." $dotFreeObject;

// we have had our way with dagMenuProc. call her a cab...
popupMenu -e -deleteAllItems cly_contextualTrash;

return $dotFreeObject[0];
}
// end: insert applause here...




result
http://farm4.static.flickr.com/3544/3444594964_b5f9dcc369_o.jpg



but what about items that have no components, such as nodes (in the hypergraph) or joints?
The above code werks for all objects ( even joints ) in the model panels.

We have to use different logic for the hypergraph however.
Thankfully this is a lot easier.
The hypergraph command can query object nodes under the cursor with the -feedbackNode flag.

fer instance hyperGraphPanel1:

/*
cly_objectHitHyperGraphMenuTemplate.mel v0.1
Roger Klado was here
because no one else will do it fer me
April 15, 2009 ( should be dom war-ing instead )
RogerKlado@gmail.com ( Klado/Claydough/cly_ )
A template for setting up object aware view pane pop-up menus
*/

global proc cly_objectHitHyperGraphMenuTemplate()
{
if( `popupMenu -exists cly_contextualTrash2` ) {
deleteUI cly_contextualTrash2;
}
popupMenu
-alt 1
-button 3
-mm 1
-p "hyperGraphPanel1HyperGraphEd"
-pmc "cly_hyperFeedBack"
cly_contextualTrash2;
}
global proc cly_hyperFeedBack()
{
if (`popupMenu -e -exists cly_contextualTrash2`) {
popupMenu -e -deleteAllItems cly_contextualTrash2;
string $feedBackNode = `hyperGraph -query -feedbackNode "hyperGraphPanel1HyperGraphEd"`;
// optionally tokenize
string $tokenizedFeedBackNode[]; // *this line for short names
tokenize $feedBackNode "|" $tokenizedFeedBackNode; // "
setParent -menu cly_contextualTrash2;
//menuItem -label $feedBackNode; // *uncomment this line for long names
// *this line for short names
menuItem -label $tokenizedFeedBackNode[size($tokenizedFeedBackNode) - 1];
}
}
// end: insert applause here...


The objects are returned with short names here. Use the long name method included to
solve for naming clashes.

result
http://farm4.static.flickr.com/3644/3443777567_384ca13e33_o.jpg


hope that helps...



// end

skunk184
04-15-2009, 04:18 PM
thanks alot Roger ...

very helpful !

cheers

Craig

CGTalk Moderation
04-15-2009, 04:18 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.