View Full Version : how script run whenever the scene is opened


DEVILSAN
09 September 2008, 07:03 AM
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).

ewerybody
09 September 2008, 08:40 AM
hi! ... ehm... what is your question? :D

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:\n" + `file -q -sn`);
}

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

DEVILSAN
09 September 2008, 09:13 PM
hi! ... ehm... what is your question? :D

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:\n" + `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"

Norb
09 September 2008, 09:50 PM
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;
}
makeWindow();


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


source makeWindow.mel;

Norb
09 September 2008, 09:53 PM
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..

NaughtyNathan
09 September 2008, 09:47 AM
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 :D


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.

:nathaN

ewerybody
09 September 2008, 11:44 AM
yea I had answering to this post on my list as well... but yea thats it :D

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

DEVILSAN
09 September 2008, 03:56 PM
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 :D


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.

:nathaN

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.

DEVILSAN
09 September 2008, 04:01 PM
yea I had answering to this post on my list as well... but yea thats it :D

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


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...

pixlix2
09 September 2008, 05:06 PM
create an annotation object in the scene that says: "turn on execute script nodes, stupid!"

CGTalk Moderation
09 September 2008, 05:06 PM
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.


1