Mel Window information

I’m trying to add a notes field into a GUI that loads and saves notes of an object. So far what I have is:

if (`window -exists "test"`) deleteUI test;
string $window = `window -t test`;
string $notes = `getAttr pSphereShape1.notes`;
columnLayout;
string $scroll = `scrollField  -wordWrap true -text $notes`;
button -l save;

showWindow $window;
renameUI window1 test;

I have a basic sphere with the original name pShere1, when I have notes under the notes window under pShereShape1 the window displays those notes. What in trying to do is be able to save what is edited in the window back to the notes on the object.

Thanks.

yeah! spent all day figuring this out and finally got it working. This is what I did:

if (`window -exists "test"`) deleteUI test;
//-------------------------------Name UI
string $window = `window -t test test`;
string $notes = `getAttr pSphereShape1.notes`;
//-----------Name UI
columnLayout testColumn;
//----------------------------------------------------------Name UI
string $scroll = `scrollField  -wordWrap true  -text $notes testField `;
button -l save -c "saveNote" ;
//Show Window
showWindow $window;

//Button Command
proc saveNote(){
string $saveNote = `scrollField -q -tx testField`;
setAttr  pSphereShape1.notes -type "string" $saveNote;
}

After I found out how to query the UI name I then had to figure out how to name UI elements, which you can do by adding the name to the very end of the code as you can see in my code I’ve entered the name under —Name UI. Then I was able to query text from the scrollField and save them back to the objects notes. WOO!

Well done :slight_smile:

I think this is a good example of where pymel, or more generally speaking python, or even more generally speaking object oriented languages really shine. Forget names, work with objects. All your troubles wouldn’t have been existent in the first place.

You both name you UI elements and throw them in variables, which is double work that you don’t need to do. Only throw elements into variables if you don’t name them (if you even need them for something later in that function, which I doubt will be often) and your code will be cleaner.

So, when it comes to “forget names”, I wouldn’t do that in Maya, and this is Maya specific due to how it works with UI elements. All UI elements are global in Maya (good and bad, but as it is this way you may as well use it). So make sure you give them a unique name and you can always reach them without having to have the variable that points at them.

It can be seen in your code as well, you use the testField inside the saveNode function this way.
If UI elements had not been global you would have needed to send the $scroll variable to that function, which you don’t need so you also don’t need to throw that UI element into a variable when you create it.