Mel script works when run through script editor, but not as a shelf button

270 views Asked by At

I have a mel script that I use if my graph editor has a visual bug where it appears blank/empty. What the script does is tears off the graph editor, closes it, and then runs the command to go to my saved panel layout called "Animation"

It works perfectly when run through the script editor, or the Mel box at the bottom of Maya, but when I save it as a button on my shelf, it will tear off the graph editor and close it, but won't run the panel layout part of the code.

I'm stumped, so if anyone knows how to get it to work as a shelf button that would be great!

if (`window -q -ex graphEditor1Window`)
    deleteUI graphEditor1Window;
else
    tearOffPanel "Graph Editor" "graphEditor" true;
    deleteUI graphEditor1Window;
    setNamedPanelLayout "Animation"; 

I have tried saving it as its own .mel file and calling it, but that hasn't worked. Nor has trying different ways of calling it through the shelf button

2

There are 2 answers

2
haggi krey On

I suppose you always want to set the layout to "Animation" so you should reformat your code like this:

if (`window -q -ex graphEditor1Window`)
  deleteUI graphEditor1Window;
else{
  tearOffPanel "Graph Editor" "graphEditor" true;
  deleteUI graphEditor1Window;
}
setNamedPanelLayout "Animation"; 

This way the graph editor window is always deleted and then always your layout is applied. This works fine for me as shelf button or as script in the script editor.

0
robthebloke On

There are a few difference between scripts in the script editor, and when running scripts via the source command (for example, via buttons in the shelf).

It's been a few years since I used Maya in anger, but Im going to take a guess that Maya is disabling windows message processing when running via source? That could cause issues if the command you are executing is expecting the message pump to have been cleared. You can probably work around this by deferring the command that modifies the layout?

if (`window -q -ex graphEditor1Window`)
    deleteUI graphEditor1Window;
else {
    tearOffPanel "Graph Editor" "graphEditor" true;
    deleteUI graphEditor1Window;
}
evalDeferred "setNamedPanelLayout \"Animation\"";