View Full Version : UI - grabbing current selection
11-28-2010, 11:40 PM
I m building a mel UI and want to grab the currently selected object to put into a textFieldButtonGrp, is this possible? Im pretty new to UI stuff but can see the difference between this object and the textScrollList where one can append objects to the list.
All I want to do is to use a button to grab the object and oput into the text field, then eventually run a command that uses that value in a procedure.
Which is the better way to go?
11-29-2010, 09:18 AM
at a very basic level, this is super easy.
first, NAME your textFieldButtonGrp control so you can -query and -edit it easily later. Then write a small global proc that queries the current selection, then edits your named textFieldButtonGrp -text flag with the first item on the returned list. Simply assign this proc to the button you press to grab the selection and you're done.
this it the basic idea in a nutshell, and I'm guessing that's all you want, but there are several problems with this if you want to get super complicated... If you use the full DAG name it looks unsightly to the user, but if you don't you have potential issues with multiple short names. Ideally you want to store the long name in a hidden area and place the short name in the textField, but this requires a slightly more complex proc to manage the textField. Additionally, a textField is just a piece of text, it has no real connection to the node itself. If you rename or reparent your node, the textField entry becomes redundant. MEL has no real "Object Button" UI that has a link to the actual node like you have in MAX (so I hear).
11-29-2010, 09:28 AM
here's a simple example:
global proc getObjectNameForField()
string $sel = `ls -sl -tr`; // get current selection (transforms)
string $firstItem = $sel;
// now -edit the textField control with our new text:
textFieldButtonGrp -edit -text $firstItem myUI_ObjectNameField;
// test UI:
window -wh 300 80;
columnLayout -adj 1;
textFieldButtonGrp -text "object name here"
-bl "grab" -bc getObjectNameForField
myUI_ObjectNameField; // make sure we NAME our field control
now, pressing the button labelled "grab" will run the proc which gets the selection and edits the field. You could fully automate this with a scriptJob that executes the getObjectNameForField proc on "SelectionChanged", but I'm not sure that's something you want here..?
11-29-2010, 08:23 PM
Thats more than anyone could ask for Nathan, thank you for that, thats exactly what I am after.
Actually my setup is pretty simple, the user selects an object pushes the button on the UI which throws it into the textfield, does that a coup,e more times in other text fields, then builds and asset based on selection - end of story.
You bring up a good point that I noticed also where the selection actually becomes a string object and no longer linked to the real object in the scene - very strange feeling to start passing around a string object that isnt even a pointer. Problems start to arise when trying to crash test the code, at the moment I can only check to see if the size(string) is greater than zero, just a little bit lame.
The only other avenue is to make sure the `ls -sl` has enough filters to get the right node. Also for example one of the selections has to be a PaintFX stroke, I know how to retrieve the shape object but how can I check to make sure its a PaintFX stroke? Because after you get the shape object it now becomes a string and I cant test a boolean on strings.
Any ideas on this point?
11-29-2010, 09:25 PM
when using ls to get names, always try to use the -type flag to specify the type of node you want returned. 99% of the time you can get an array of exactly what you want just using ls and maybe one other list____ command. If you start trying to process an ls array in a for...loop you are wasting a potentially huge amount of processing time.
If you want to find out what type a particular node is use the -showType flag first:
ls -sl -dag -showType;
// Result: strokeBrush11 transform strokeShapeBrush11 stroke
now you can do this:
ls -sl -dag -type "stroke";
// Result: strokeShapeBrush11
to get any selected brush stroke nodes, etc..
11-29-2010, 09:53 PM
got it. I will use showType in the future.
Thanks again you have been very helpful.
11-29-2010, 09:53 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.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.