Skip to content

Instantly share code, notes, and snippets.

@oglops
Last active September 6, 2021 03:06
Show Gist options
  • Save oglops/809d39aebe48bd0aa204b16b8955ed03 to your computer and use it in GitHub Desktop.
Save oglops/809d39aebe48bd0aa204b16b8955ed03 to your computer and use it in GitHub Desktop.
sync maya script editor tabs among multiple maya sessions
import re
import maya.cmds as mc
import maya.mel as mel
def get_optionvar(var, type='iv'):
pref_file = mc.internalVar(userPrefDir=1)+'userPrefs.mel'
values = []
with open(pref_file) as f:
for line in f.readlines():
match = re.search(
'(?<=\s-{type}\s"{var}"\s)(?P<value>[^;\n]*)'.format(type=type, var=var), line)
if match:
value = match.group('value').strip('"')
values.append(value)
if len(values) == 1:
values = values[0]
return values
def save_tabs():
cmd = '''
syncExecuterBackupFiles();
syncExecuterTabState();
savePrefs -general;
'''
mel.eval(cmd)
def load_tabs():
cmd = '''
global string $gCommandExecuterName[];
global string $gCommandExecuterType[];
global string $gCommandExecuterTabs;
deleteUI `tabLayout -q -ca $gCommandExecuterTabs`;
python("from syncScriptEditor import get_optionvar");
$gCommandExecuterName=python("get_optionvar('ScriptEditorExecuterLabelArray','sva')");
$gCommandExecuterType=python("get_optionvar('ScriptEditorExecuterTypeArray','sva')");
{
int $len = size($gCommandExecuterName);
int $i;
for ($i = 0; $i < $len; ++$i) {
buildNewExecuterTab($i, $gCommandExecuterName[$i], $gCommandExecuterType[$i], 0);
}
int $prevIdx = python("get_optionvar('ScriptEditorExecuterTabIndex','iv')");
tabLayout -e -selectTabIndex $prevIdx $gCommandExecuterTabs;
}
'''
mel.eval(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment