PDA

View Full Version : Max style picker button using MEL


Klunk
09-19-2005, 07:17 PM
Hi,

I'm having trouble implementing an "object picker" button using Mel. If someone could point me in the right direction I would be very grateful.

claude

jtilden20
09-19-2005, 09:10 PM
Here is something I've done in the past to mimick this behavior:

When you press the 'pick' button:
1.) Change the color of the button to inform the user that you're in pick mode.
2.) Start a scriptJob and specify a callback to occur when the selection changes.
3.) When user is done selecting, have them click the 'pick' button again to disengage pick mode.
4.) Change the color back to inform user that they're no longer in pick mode
5.) Delete your selectionChanged scriptJob.

That's about it! Let me know if this helps!
-Jon

harmless
09-19-2005, 09:48 PM
When the button is pressed change the text to "Select Object"
(look under window/ui category in mel commands)

Run a scriptJob that looks for a change in selection
(look in the mel commands for scriptJob)

When the selection changes grab the first element in the array
string $allSel[] = `ls -sl`;
string $obj = $allSel[0];)

Update the UI with the name of $obj

Klunk
09-20-2005, 10:42 AM
thanks guys

the result came out like this, it works after a fashion, a version without the global would be nice but i can't get the scriptJob script call to except arguments.


global string $gtheSel;
global string $gtheButton;
global vector $gtheButtonBGColour;

window -title "Test Window" -widthHeight 200 100 testWindow;
columnLayout;

// Create a button and add a command.

$gtheButton= `button -label "Pick Object"`;
button -edit -command ("buttonCommand " + $gtheButton) $gtheButton;

showWindow testWindow;

proc buttonCommand(string $whichButton)
{
button -edit -backgroundColor 1.0 0.8 0.0 $whichButton;

// filter for our object type

selectType -allObjects false;
selectType -polymesh true;

// run the job

scriptJob -runOnce true -ct "SomethingSelected" "GrabSelection";
}

proc GrabSelection()
{
global string $gtheSel;
global string $gtheButton;
global vector $gtheButtonBGColour;
string $allSel[] = `ls -sl`;

selectType -allObjects true;
$gtheSel = $allSel[0];

// tell the user the selection

button -edit -label $gtheSel $gtheButton;
button -edit -backgroundColor 0.828125 0.8125 0.78125 $gtheButton;
}

CGTalk Moderation
09-20-2005, 10:42 AM
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.