Hi there!
To start with: I have NO BLOODY IDEA of scripting!
Back in the 80s, I used to write code for my machine (Atari 800XL- 64KB!) in Basic and Assembler, but that was then...
The situation now is as follows: first I've assigned a couple of commands to a hotkey (Ctrl+Alt+F12).
When pressed, it executes a mel-script which opens a number of windows/panels.
The code goes like this:
tearOffPanel "Outliner" "outlinerPanel" false;
openAEWindow;
renderGlobalsWindow;
toolPropertyWindow -inMainWindow false;
tearOffPanel "Multilister" "multiListerPanel" true;
tearOffPanel "Visor" "VisorPanel" true;
There is no problem when I run the script via a hotkey call from within Maya, but when executed as a userSetup.mel at startup, I receive the following error message (in the Script Editor):
// Error: Object not found: VisorPanel //
file -f -new;
select -cl;
// Result: ./untitled //
(I dont't even have the faintest idea if the last three lines are part of the error message or something entirely different.)
As you might have guessed, all the windows but the Visor open correctly.
So what is the point? Why does it work when linked to a hotkey, and why does it fail when run as a userSetup.mel-script?
And please: keep your answer simple - I don't want to go back to the days of old, when I sat night-long, breeding over a piece of utterly spaghettied code trying to find the wrong conditional branch (BNE? BPL? BEQ? Forgotten to re-shift the registers before leaving the DLI?)...not yet, that is!
Thanks anyway!
Renderizer
The reason it was failing on you is because many parts of Maya's UI (like Visor) hasn't finished initializing when userSetup is sourced. You need to use evalDeferred so that the tearOffPanel command executes on the next idle event (usually after the empty scene is created). The following code should work in your userSetup:
//begin------------------------------------------------------
tearOffPanel "Outliner" "outlinerPanel" false;
openAEWindow;
renderGlobalsWindow;
toolPropertyWindow -inMainWindow false;
tearOffPanel "Multilister" "multiListerPanel" true;
evalDeferred("tearOffPanel "Visor" "VisorPanel" true"); //evaluates the command at the next idle event
//end--------------------------------------------------------
I personally prefer that custom UI configurations are saved with the scene file by using a script node.
Create a new file, then paste and run the code below in your script editor. Then save the file with a meaningful name. Now whenever you need to start a new file with that specific UI then just open the file you saved. You can view/create/modify script nodes via the expression editor.
//begin------------------------------------------------------
createNode script -n "myCustomUI";
setAttr ".before" -type "string" (
"tearOffPanel "Outliner" "outlinerPanel" false; rn"
+ "openAEWindow; rn"
+ "renderGlobalsWindow; rn"
+ "toolPropertyWindow -inMainWindow false; rn"
+ "tearOffPanel "Multilister" "multiListerPanel" true; rn"
+ "tearOffPanel "Visor" "VisorPanel" true; rn"
+ "r");
setAttr ".scriptType" 2; //GUI Open/Close
//end--------------------------------------------------------
To learn more about script nodes see the command documentation for scriptNode and the node documentation for script.
Hi Scifiwasabi,
Thanks a lot for your help.
I use this configuration as a startup layout for the second monitor.
I've assigned a couple of hotkeys to some other windows/panels, so I can change between them as needed.
Well, I hope one day I'll start to do some scripting on my own, but the time has not yet come.
I guess that it wouldn't be too diffcult for me, as I have written a lot of tools in 6502c Assembler and BASIC, as well as some wee little routines in Action!, but that was back in the early/midlle 80s.
We'll see...
Al the best,
Renderizer