Maya optionVar question

Where/how are maya’s optionVars saved?

I often have multiple mayas open and I’d love to be able to have something like the recent files list reflect all files I’ve opened across all sessions (like it does in Nuke), and for them to persist even if maya crashes, or set vars from multiple sessions and know they’ll be there when I reopen. Is this possible?

optionVars are stored in MEL files. The entries are just key/value pairs. The are saved when Maya closes (usually), but you can force them to be saved by doing File->Save Preferences (or in code).

The recent files list (key is ‘RecentFilesList’) entry is stored in the:
C:/users/name/Documents/maya/2013-x64/prefs/userPrefs.mel file

To get a list the recent files, you can do:


import maya.cmds as cmds
cmds.optionVar(query='RecentFilesList')

To save a list of files, you can do something like:


import maya.cmds as cmds
cmds.optionVar(stringValueAppend=('RecentFilesList', 'path/to/recent/file/you/want/to/add.ma'))

The other MEL files where preferences are saved (you can see this in the script editor output if you do File->Save Preferences):
// Saving preferences to : C:/Users/name/Documents/maya/2013-x64/prefs/userPrefs.mel //
// Saving window positions to : C:/Users/name/Documents/maya/2013-x64/prefs/windowPrefs.mel //
// Saving runtime commands to : C:/Users/name/Documents/maya/2013-x64/prefs/userRunTimeCommands.mel //
// Saving hotkeys to : C:/Users/name/Documents/maya/2013-x64/prefs/userHotkeys.mel //
// Saving named commands to : C:/Users/name/Documents/maya/2013-x64/prefs/userNamedCommands.mel //
// Saving plug-in preferences to: C:/Users/name/Documents/maya/2013-x64/prefs/pluginPrefs.mel //
// Preferences saved. See Script Editor for details. //

Phil

recent files end up in userPrefs.mel on save. You can tweak the list with the mel command addRecentFile

<EDIT>
… ooh, beaten to the punch :slight_smile:

Ah, didn’t realize where they were saved.

I was curious about getting multiple maya sessions to update the recentFilesList and not clobber each other. Since it seems like Maya loads the optionVars into memory when it starts, the only way I can think of to do that is to read the optionVar from the userPrefs file before saving it and updating it with anything I’ve opened in the current session and writing that out. It was more of an “I’m curious, how would I…” than something I’m going to try and implement. Either way I figured it’d be cumbersome and it seems to be!

You could alway send the file updates to other maya instances on the command port if you really wanted to. Otherwise they are completely isolated from each other during their lifetimes (a source of endless hassle if, for example, you set a plugin to auto-load in session b but save/close session b later – boom, no plugin !)