PDA

View Full Version : Auto Save Script - help please


theazz
11-03-2010, 02:30 PM
hey guys

im not that experienced in MEL, but im trying to write a script i would like lots of artists / animators around my company to be able to use, it has to be as use friendly as possible, its an auto save script.

im having 2 issues currently

firstly, i want the options window for this to be available near all the other save related stuff in the file menu, ive seen other scripts do this and it makes it consistent and easy for artists to find.

currently im doing this

global string $gMainFileMenu;
string $menuItem[] = `menu -q -ia $gMainFileMenu`;
if (stringArrayCount("srOptionsMenu", $menuItem)==0)
{
setParent -menu $gMainFileMenu;
menuItem -label "Save Reminder Options" -annotation "saveRemindAD Options" -command "srAD_options" -ia $menuItem[7] srOptionsMenu;
setParent -m ..;
}

if i source this during a session of maya it works well, however, if its sourced through userSetup.mel, it replaces and the entire file menu so there is only this, disaster!

secondly, being a script which works silenty, it has to basically initialise a scriptjob on mayas startup. now i know i could get people to edit / create there userSetup.mel files but its not very artist friendly. i want to easily be able to "install" the script

my only thought is that i could in MEL check to see if the userSetup.mel file and if they do edit it, if they dont create it, but ive hit a bit of a block in that when i quiry the maya env's to get the script path, i get loads when i just want the normal one at "C / docs n settings / maya / 2010 / scripts etc" - while obviosuly being platform / version / OS independent so it works for all

any thoughts? thanks in advance

NaughtyNathan
11-03-2010, 04:09 PM
evalDeferred any changes to the file menu and this should help.

no need to query the script path, simply use this to get the userSetup:
whatIs userSetup.mel;which will both tell you if it exists AND give you the full path to it. however, if you don't find a userSetup and need a path to create one use this:
string $scriptPath = `internalVar -usd`;Maya 2011 has auto save built in, maybe it's time to upgrade?

:nathaN

theazz
11-03-2010, 04:58 PM
thankfs for your reply

the WhatIs command returns the first of many userSetups there seems to be on the multiple scriptpaths, is there any way i can get just the one in the my docs path? its returning one from our SDK which i dont really wanna edit

yeh i know 2011 has autosave, my script will include more features such as reminders like motion builder has rather than automatically save.

EDIT

sorry i didint try that second bit of code u posted, that seems to have done what i asked about returning just the my docs one, how did u learn about thisstuff, where is there a resource for this, like these internal vars?

thanks a lot

NaughtyNathan
11-03-2010, 05:18 PM
the point is you can only have ONE file found on a path. it doesn't matter if your user has 127 usetSetup.mel files, Maya can and will only load one, and this is the first one whatIs finds. this is how 'paths' work. Getting the one in your scripts path, and relying on this may be a grevious error, as, if it is not the first one found, will not be loaded anyway.

I learned all this stuff slowly by MEL scripting almost constantly for 8-9 years. digging in Maya's internal Mel files is the way to learn all the clever and secret tips! ;) Also, if you work in a studio with other MEL scripters (as I have), you can pick up twice as much by sharing any nuggets of info like this. (and by constantly reading this forum too of course!)

:nathaN

theazz
11-03-2010, 05:24 PM
weird, so ur saying that the userSetup.mel in my docsuments/maya/blah blah folder folder isnt loaded? since another one is found my the whatIs?

because at the moment when i source my script from the userSetup.mel in the my documents it seems to do as i say in the first post, killing the file menu, suggesting that it does get loaded.

mduvekot
11-03-2010, 07:39 PM
I don't think userSetup is your biggest problem. Yes, there's just the one, so it should be in the right location. Check that it doesn't mess with bonusTools, which also depends on userSetup.

The bigger problem is that userSetup.mel gets executed before the item that you want to insertAfter exists.

I get // Warning: file: /Users/michiel/Library/Preferences/Autodesk/maya/2011-x64/scripts/userSetup.mel line 11: Menu item saveAsItem does not exist, flag -insertAfter ignored. //

so what I would do is make a scriptJob that gets triggered by creating the File menu.

something like this:


global proc doIt() {
global string $gMainFileMenu;
string $menuItem[] = `menu -q -ia $gMainFileMenu`;
print "//-------add sr Menu --------\n";
print $menuItem;

if (stringArrayCount("srOptionsMenu", $menuItem)==0) {
setParent -menu $gMainFileMenu;
menuItem -label "Save Reminder Options" -annotation "saveRemindAD Options" -command "srAD_options" -ia "saveAsItem" srOptionsMenu;
setParent -m ..;
}
}


global proc int mainFileMenuExists() {
global string $gMainFileMenu;
return (`menu -q -ni $gMainFileMenu`);
}

condition
-d "idle"
-initialize
-s "mainFileMenuExists"
mainFileMenuOK;

scriptJob -conditionChange "mainFileMenuOK" "doIt" -ro true;

theazz
11-04-2010, 09:45 AM
thanks for all your help guys

i found out why multiple userSetups were sourcing, the "first one" sources all the other ones

mduvekot: i tried ur code and it didn't do anything, although it might be me i don't understand properly all the condition / scriptjob stuff or how its supposed to work, but thanks!

CGTalk Moderation
11-04-2010, 09:45 AM
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.