Tips: Use an if-statement before UI creation

Hello everybody. Today I’m going you to share with you a tips about writing UI in MEL.

 

When you write an UI in MEL, and let’s say, you add a button to the window, and eventually execute it, your UI, if there be no syntactical mistake, will pop up. Then you need to add another button, regularly you close the window and add your textual line and rerun the script.

If you don’t close your window, and apply changes and call your script for an execution, you will see an error which reads:

// Error: line 1: Object’s name ‘testWindow’ is not unique. //

This error is very common that sometime it might transform your health into a headache.

The most common interlude of this error is in non-displayed windows. What do I mean?

If you execute the following code, your window will not popup, while the declaration of the window has happened, and only the button creation has encountered a problem, a syntactical problem.Try this code:

//

window -t “This is a test window” testWindow;

button testButton -w 100; // Note that this line is syntactically wrong, and errs.

showWindow mm;

//

In our button line, the second line is meant, we have made a wrong syntax which is unknown to Maya; therefore, Maya doesn’t understand it and breaks the execution process, which will result in no displaying of the UI.

But Maya has made a space in his memory allocation, and registered there a window with the node’s name “testWindow which will collide with recreation of the same window having the same name applied, if you change the name of your window everything calms down and your process comes routine, but is it really possible each time you change your window node’s name?

If you tell Maya if such name already exists, please delete, and the naturally Maya if the case be true will do that.

//

if (`window -exists testWindow`)

{

deleteUI testWindow;

}

//

Just place this script before any window declaration in any script, and then change the name in conditional statement to your window’s name.

our script will look like this:

if (`window -exists testWindow`)

{

deleteUI testWindow;

}

window -t “This is a test window” testWindow;

button testButton -w 100; // Note that this line is syntactically wrong, and errs.

showWindow testWindow;

//

 

 

I hope this tip come to be useful.

mostafatalebi@rocketmail.com

artixel.wordpress.com