PDA

View Full Version : Referenceable Custom RMB Menu


KIIIA
12-04-2011, 09:55 AM
Hello,

i'm searching for a good tutorial on how to make a referenceable custom RMB menu.
In particular i want to setup a RMB menu to realize Parent-Space Switching for manipulators of a character.

If possible the method should not involve any necessity to copy custom scripts on the machines that reference the file in.

Does anybody have some good tutorials on that?

thematt
12-04-2011, 12:45 PM
don't know any tut about that, but this is doable using the script node take a look at it..you could then insert the dagmenu script in it and have it exectute that way inside your file anytime.

hope it helps

KIIIA
12-04-2011, 03:50 PM
Thx for your reply, i was kinda thinking that it should be possible with this node somehow! How exactly could the namespaces be handled? Would the script look something like:
1 - Check which node i'm rmbing over
2 - If that nodes name (without namespaces) equals a given name i want to have my custom rmb for
3 - Append namespaces to all other nodes i want to access by rmb script and execute it

PS: Is there a way to do this with pymel, since i'm much more familiar with that?

mlefevre
12-04-2011, 10:16 PM
This isn't fully tested but, like thematt says, scriptNodes should do the job.

Copy the contents of dagMenuProc.mel into a scriptNode.

Find this line in the dagMenuProc procedure..
string $shortName = `substitute ".*|" $object ""`;

..edit it to look something like this
string $shortName = `substitute ".*|" $object ""`;
if(`isCustomMenuObj($shortName)`)
{
buildCustomMenu($shortName);
}
else
{

Set the scriptNode to execute on Open/Close and you've set it to 'Before'. Name it as CustomDMP or something.

Create another scriptNode, with the same settings.
Add the following..

scriptNode -executeBefore "CustomDMP";

global proc int isCustomMenuObj(string $obj)
{
string $controls[] = {"locator1"};

string $buffer[];
tokenize($obj, ":", $buffer);

return stringArrayContains($buffer[size($buffer)-1], $controls);
}

global proc customCommands(string $control)
{
move -r 0 1 0 $control;
}

global proc buildCustomMenu(string $control)
{
menuItem -label "Custom Command" -radialPosition "N" -command ("customCommands(\"" +$control + "\")");
}

That's pretty much what you've already mentioned. Just find the name of the object, remove the namespace, check if it's part of a defined list of controls and if so build the custom menu for it.
It's not fully tested, but maybe it's a start.

KIIIA
12-05-2011, 12:03 AM
Given this approach, what happens if i reference several characters in with custom second script nodes. Wouldnt the last processed (referenced) scriptnode override the search strings of the other scriptnodes, making only the last referenced object rmb-able?

(Referencing in the same object several times should work i guess because teh object names are the same and we care about the namespaces)

--
Tested it! First, your code works nice mlevefre, thx! But as i was assumeing, the problem with having several object script nodes overriding the earlier search strings happens as well! If there are several different chars in the scene, it will get screwed!
Any ideas on how to solve that? Like only adding search strings to a scene based kind of search string library scriptNode ?

mlefevre
12-05-2011, 02:01 AM
Well there's probably a few ways to go about it. Perhaps instead of a list of controls, you just tag whichever nodes you want custom menus with an attribute, then check if that attribute exists on the node before building the menu.
I also noticed it might not work if you just boot up maya and reference in the file, but this might fix it.

Change:
scriptNode -executeBefore "CustomDMP";

to this..
if(`objExists "CustomDMP"`)
{
scriptNode -executeBefore "CustomDMP";
}
else
{
namespace -setNamespace ":";
string $namespaces[] = `namespaceInfo -listOnlyNamespaces`;
for($name in $namespaces)
{
if(`objExists ($name + ":CustomDMP")`)
{
scriptNode -executeBefore ($name + ":CustomDMP");
}
}
}

I'm actually unsure why it's even necessary to use scriptNode -executeBefore customDMP, since customDMP should be executed upon opening the file (& I assume this includes referencing). But without it, it doesn't seem to work. If you find out why...let me know hehe!

KIIIA
12-05-2011, 06:44 PM
Honestly, i actually never used that piece of code since i expected it to execute on opening/referencing anyways! Works pretty without so far! :D

mlefevre
12-05-2011, 07:17 PM
Honestly, i actually never used that piece of code since i expected it to execute on opening/referencing anyways! Works pretty without so far! :D

That's odd. It doesn't work for me without that line, although I would have thought it should.

I still don't fully know when dagMenuProc is actually sourced. If it's during maya loading, then redeclaring the dagMenuProc procedure at any point after that should overwrite it, including within scriptNodes. *shrug*

I'd personally stick to keeping most of code outside of the file. It looks as though it can get pretty messy embedding all the code within scriptnodes, but good luck either way :)

KIIIA
12-06-2011, 11:25 PM
Hmm you were right mlefevre! Dont know why i thought it would work without that extra bit of code yesterday........but when i finetuned my solution today, it turned out that it does not!

Apart from that it works great! I just like that code inside the file since i consider that a part of the rig. I think it was disturbing if people couldnt fully use the rigged character without custom scripts!

CGTalk Moderation
12-06-2011, 11:25 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.