how script run whenever the scene is opened


A script node lets you attach a MEL script to a scene, and have the script run whenever the scene is opened (loaded from disk) or closed (when the user opens another scene file or starts a new scene).


hi! … ehm… what is your question? :smiley:

concerning your topic title I’d suggest to use a “SceneOpened”-scriptJob. Try the following:

scriptJob -event SceneOpened "myTestProc";
 global proc myTestProc()
 	confirmDialog -t myTestProc -m ("you opened the scene:
" + `file -q -sn`);

besure to put the scriptJobID into a variable to be able to kill it, or attach the scriptJob to a UI!


where should i put this code in my scene file, so as when maya scene file is opened it should execute and show this message “you opened the scene”


It’s not too complicated…

  1. Make a script and put it in one of your script folders that is defined in your maya.env file.
  2. Edit your userSetup.mel file so that it sources and/or runs your script. Mine is located here: C:\MyPersonalData[username]\maya\8.5\scripts
  3. Start maya.

as an example, try this:

Save this as ‘makeWindow.mel’ in your maya startup folder: C:\AW\Maya8.5\scripts\startup

global proc makeWindow()
	string $sWin = "tempWin";
	if (`window -q -exists $sWin`)
		deleteUI $sWin;
	window $sWin;
	showWindow $sWin;

then edit your userSetup.mel so that it contains this line:

source makeWindow.mel;


As a follow up, once you get that working, you can make your script startup a script job that will do stuff when you open a scene, etc…


I think you guys have got the wrong end of the stick… he want’s to know how to run a script when a particular scene is opened (I think, his original post is mind-bogglingly vague). This seems to be verified by the fact that he later asks “how to put the script in my scene”.

I’m guessing he wants to know how to create a scriptNode. so I’ll tell you whether you want to know or not :smiley:

string $mel = "confirmDialog -m \"You've loaded the scene!\";evalDeferred(\"OutlinerWindow\")";
string $SN = `scriptNode -scriptType 2 -bs $mel`;

execute the code above in a scene and then (once saved, duh!) whenever you load the scene it will pop-up a dialog box and open the outliner window. It should be obvious enough to see how it works to adjust the MEL code you want to run.



yea I had answering to this post on my list as well… but yea thats it :smiley:

one thing: You NEED to have “Execute Script Nodes” enabled in File > Open Scene Options!


well, it was only NORB who didnt got it, thanks nathan, thats exactly what i wanted… in the first post i just copied the text from maya help and pasted in here becasue that what i was looking for and the maya help too referred to some other book.


yea this is also the point , if this option is not checked on so how should i tell one who open scene file to enable execute scripts, and give him message… coz otherwise its of no use…


create an annotation object in the scene that says: “turn on execute script nodes, stupid!”


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.