View Full Version : Get parent of UI element?
Harrad 03-30-2009, 01:39 PM Hey guys,
Don't know if i'm overlooking something really obvious here but i can't seem to find a way of finding out the parent layout of a UI element.
All my elements/layouts are named and i can't find anything in the mel help.
- string $parent = `listRelatives -p btn_test`; ** you can't seem to call this on UI elements
- string $parent = `button -q -p btn_test`; ** the parent flag isn't queriable.
this seems really easy on objects but not on UI... any ideas?
thanks
|
|
cbamber85
03-30-2009, 01:50 PM
string $parent = `button -q -p btn_test`;
Works for me. Bare in mind it doesn't just return the immediate parent, it returns the entire UI hierarchy from the specified control right up to the window, separated by |.
Harrad
03-30-2009, 02:07 PM
really? how are you implementing that?
i just did a quick test ...
proc test_buttonParent()
{
string $parent = "not yet definded";
window -width 150;
columnLayout -adjustableColumn true;
button -label "test button" btn_test;
showWindow;
$parent = `button -q -p btn_test`;
//EDIT THE COMMAND OF THE BUTTON
button -e -c ("print\"" + $parent + "\"") btn_test;
}
test_buttonParent;
and nothing seems to be returned?
cbamber85
03-30-2009, 02:21 PM
I just copied your code into my script editor, ran it, the window appeared, I pressed the button - and this came out:
window1|columnLayout32
Not sure what to suggest now...
Harrad
03-30-2009, 02:25 PM
humm... thats very wierd.
if i echo all commands i get this when i press the button...
print"";
I can't see why it would work on your and not mine... what version of maya are you using, i'm on 2008.
Harrad
03-30-2009, 02:31 PM
ok... so i just found out that you can query the setParent command. so a small tweek to the code...
proc test_buttonParent()
{
string $parent = "not yet definded";
window -width 150;
columnLayout -adjustableColumn true;
button -label "test button" btn_test;
showWindow;
string $parent = `setParent -q btn_test`;
//EDIT THE COMMAND OF THE BUTTON
button -e -c ("print\"" + $parent + "\"") btn_test;
}
test_buttonParent;
and this now works. I still can't figure out why the old version worked on your maya and not mine....
but any way problem solved.
Thanks for your help cbamber85 :D
Robert Bateman
03-30-2009, 02:32 PM
window;
columnLayout;
button -l "foo" button_1;
showWindow;
print `button -q -p button_1`;
works fine for me? can even do:
setParent `button -q -p button_1`;
button -l "bar";
and it all works....
cbamber85
03-30-2009, 02:36 PM
2009, but what we're doing is so simple it shouldn't make any difference. At times like these, and good turn off and on again is recommended. :)
CGTalk Moderation
03-30-2009, 02:36 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-2012, Jelsoft Enterprises Ltd.