Mel command save contents of script editor tabs and MTK shelf.

Mel command save contents of script editor tabs and MTK shelf.

malcolm_341
Collaborator Collaborator
4,128 Views
14 Replies
Message 1 of 15

Mel command save contents of script editor tabs and MTK shelf.

malcolm_341
Collaborator
Collaborator

I'm looking for two commands, one to save the contents of the script editor so if Maya unexpectedly exits I don't lose my work. And the second command I'm looking for is how to save the modeling toolkit built in shelf for the same reason. Both these things are saves when Maya quits so I'm hoping there's commands for them somewhere.

0 Likes
Accepted solutions (1)
4,129 Views
14 Replies
Replies (14)
Message 2 of 15

stuzzz
Collaborator
Collaborator

If for some reason Maya crash you can still recover your script editor content.

Go in that folder (windows) C:\Users\<yourname>\AppData\Local\Temp

 

you will find the *.ma saved during the crash and the scripteditor content.

grabScreen_147114524.jpg

0 Likes
Message 3 of 15

malcolm_341
Collaborator
Collaborator

Thanks, that's super handy, but I also want to create a script which kills Maya without it taking 13 seconds to close. I have the script working, but I need to include the saving of the script editor and contents of the MTK shelf so I still need the commands for those. Right now when I run my script it doesn't remember what I've done in the script editor.

0 Likes
Message 4 of 15

fowlert
Autodesk
Autodesk

syncExecuterBackupFiles  is the name of the MEL proc that saves your script editor tabs, it's in scriptEditorPanel.mel

0 Likes
Message 5 of 15

fowlert
Autodesk
Autodesk
Accepted solution

And the proc for MTK shelves is dRSaveShelves, that's in drInit.mel.

0 Likes
Message 6 of 15

malcolm_341
Collaborator
Collaborator

Nice, thanks a lot.

0 Likes
Message 7 of 15

malcolm_341
Collaborator
Collaborator

Edit post, never mind it seems to be working as intended now. Nothing to see here.

0 Likes
Message 8 of 15

malcolm_341
Collaborator
Collaborator

So sometimes when I run this command it deletes all my scripts tabs off the hard drive and when I restart Maya there's nothing there but empty tabs. What's the trick to using this command safely?

0 Likes
Message 9 of 15

fowlert
Autodesk
Autodesk
Hmm...not sure what could be doing that.  Both of those functions work in their own folders so they shouldn't be touching anything else.  What exactly do you mean by "my scripts tabs"?  What folder is being deleted?
0 Likes
Message 10 of 15

malcolm_341
Collaborator
Collaborator

Often when I use this command syncExecuterBackupFiles and then kill the Maya process and restart my script tabs in the script editor will be there, but they won't have any data in them. Upon looking in this folder C:\Users\malco\Documents\maya\2020\prefs\scriptEditorTemp the text files are empty. Sometimes it works fine, but often it just wipes out all my wip scripts. Perhaps the Maya process is dying too quick and it didn't have time to write out the files. I also noticed that the user prefs file stores some data about the script tabs and what they're named. Here's my script so far which sometimes works fine, and sometimes I lose my script tabs contents. Do I need to eval deferred, and if so how do I use this command?

{
	//Save script editor tabs to temp folder
	syncExecuterBackupFiles();

	//Save all preferences
	SavePreferences;

	//Save all shelves
    global string $gShelfTopLevel;
	saveAllShelves $gShelfTopLevel;

	//Save MTK shelf
	dRSaveShelves;

	//Save tool settings
	saveToolSettings;
	saveViewportSettings;
	
	//Save scene if changed
	saveChanges("");
	
	//Close Maya
	system("taskkill /IM maya.exe /f /t");
}

 

Message 11 of 15

fowlert
Autodesk
Autodesk

Well this is a very non-standard kind of request, but it at least looks like it should work, unless something in the middle of all of that does an evalDeferred.  If that’s the case then yes, the taskkill would run before it ever got to the idle queue and you should try putting that in an evalDeferred as well.

 

I’ll admit that I’m a bit confused as to why you’re doing this though.  It’s common to set Maya to NOT save all pref’s when closing, partly as a way to not mess up your pref’s and partly I think as a way to close quicker, but you’re kind of doing the opposite here.  How long does it take Maya to close for you?

0 Likes
Message 12 of 15

malcolm_341
Collaborator
Collaborator

My Maya is incredibly slow to close, taking 15-30 seconds each time I close it. When I use this script it closes in 3 seconds and behaves the same as Maya's regular closing of the app, except for that one bug I'm running into. I read the documentation on eval deferred and it didn't make any sense to me, do you have an example how I should use that on the last command to keep it from closing too early.

0 Likes
Message 13 of 15

fowlert
Autodesk
Autodesk

Not saying that this will work, but here's what you'd do if you want to defer the running of that last line.

evalDeferred ("system(\"taskkill /IM maya.exe /f /t\");");

 

This might make a difference IF one of the earlier calls end up deferring something.

 

For the shut down performance problem, have you tried unloading any plugins that you don't actually use?  

0 Likes
Message 14 of 15

malcolm_341
Collaborator
Collaborator

Yeah unfortunately I've already unloaded all the plugins I don't use which drastically speeds up Maya start, but has no affect on Maya close. I've also tried the suggested Maya close fix of turning off the bug report stuff in the usersetup.mel and it also has no affect on Maya close speed. I'll give eval deferred a try and see what happens, and report back. I've corrupted my preferences three times already testing this so it's been time consuming figuring out where the bug is.

0 Likes
Message 15 of 15

malcolm_341
Collaborator
Collaborator

Okay so I believe I've found the problem with this command syncExecuterBackupFiles()

It appears the script editor has to be visible or the command will bug out and delete all your script tabs without you knowing until you restart Maya to find they're gone. I guess I could pop open the script editor save the tabs then close it and then run the rest of the script and then kill Maya at the end. I'll report back if it works.

 

0 Likes