PDA

View Full Version : execute a MEL script when file is opened


lilli
10-13-2004, 01:02 AM
Hi all,

I'm looking for a way to execute a MEL script that determines weather a file is read-only and warns the user if they are currently viewing a file which they will not be allowed to save.

I know how to do this, except for the part where the script is run whenever a file is opened.

I saw in the documentation that there is a scriptNode that can be attached to a file to run a command when the file is opened, but I don't want to make people attach a new node for each new file they make.

Is there any way that this can be done transparently? For instance, perhaps by adding something to a config file somewhere--all files will run a certain script on startup. Does anyone know of a way to do this?

Thanks all!
-Lilli

LoneCanuck
10-13-2004, 09:12 AM
Not an elegant solution nor will be what you are looking for but you could create a mel script that uses the OpenFileDialog command, do a check on the file selected to see if it's Read/Write, then spit back some output or a popup that alerts the user (which you probably already have). Take that script and save this as a button in your shelf.

So everytime someone opens a file, they will need to use the button to check if the file is read/write or not. :(

LoCK

orljustin
10-13-2004, 01:18 PM
Hi all,

I'm looking for a way to execute a MEL script that determines weather a file is read-only and warns the user if they are currently viewing a file which they will not be allowed to save.

I know how to do this, except for the part where the script is run whenever a file is opened.

I saw in the documentation that there is a scriptNode that can be attached to a file to run a command when the file is opened, but I don't want to make people attach a new node for each new file they make.

Is there any way that this can be done transparently? For instance, perhaps by adding something to a config file somewhere--all files will run a certain script on startup. Does anyone know of a way to do this?

Thanks all!
-Lilli
Hi,

Either put something in everyone's userSetup file to run something on fileLoad (scriptJob) or use the scriptNode.

oj

mrgoodbyte
10-13-2004, 03:02 PM
As far as I know the "Open" menu command is in fact already somesort of a script since it's not just opening a file, but also adding the item to the favorites list using mel. Just check the script editor.
So just do a search in the default maya mel files, I'm pretty sure you'll be able to find the procedure for opening files right there.

-Ronald

lilli
10-13-2004, 07:31 PM
Thanks for all the helpful responses everyone!

I ended up going with a scriptjob in the userSetup.mel that our art team shares. I was a fool not to think of a scriptJob earlier, but I don't have much experience with them.

For the curious and helpful, the final solution looks like:

//this will warn the user if they are opening a read-only filescriptJob -event "SceneOpened" "source ReadOnlyWarning.mel" -permanent;

in the userSetup and then the ReadOnlyWarning.mel script just goes

//if this file is not writable, display something
if(!`file -q -w`)
{
if(!`window -exists ReadOnlyWarning`)
window ReadOnlyWarning;
columnLayout;
text -fn boldLabelFont " WARNING!: ";
text "You do not have permission to change this file.";
text "Please check out the file if you wish to edit it.";
setParent ..;
showWindow ReadOnlyWarning;
}

Thanks again,
-Lilli

CGTalk Moderation
01-19-2006, 12:00 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.