Copy link to clipboard
Copied
Hi everybody,
I have a checkbox defined as this:
var passThrough = groupTwo.add ("checkbox", undefined, "passThrough");
And I'm trying to store the checkbox value in the AE Preference setting file, using this code here:
passThrough.onClick = function(){
app.settings.saveSetting("EVLCopy", "passThrough", passThrough.value);
}
It doesn't work.
The getSetting method doesn't work neither (over a setting that already exists in the file):
passThrough.onClick = function(){
var testing = app.settings.getSetting("AE_OpenGL","Downsample Factor");
alert(testing);
}
What the heck am I doing wrong?
Two things you are doing wrong here:
1. You are saving and getting settings from 2 different Section Names: EVLCopy and AE_OpenGL. It's a common practice to use Section Name as your Script Name. This way all your settings reside in same place, and everyone is happy.
app.settings.saveSetting(sectionName, keyName, value)
app.settings.getSetting(sectionName, keyName)
2. Optional - you need to save settings to disk to see the changes in the prefs.txt file;
app.preferences.saveToDisk();
Read more about set
...Copy link to clipboard
Copied
Two things you are doing wrong here:
1. You are saving and getting settings from 2 different Section Names: EVLCopy and AE_OpenGL. It's a common practice to use Section Name as your Script Name. This way all your settings reside in same place, and everyone is happy.
app.settings.saveSetting(sectionName, keyName, value)
app.settings.getSetting(sectionName, keyName)
2. Optional - you need to save settings to disk to see the changes in the prefs.txt file;
app.preferences.saveToDisk();
Read more about settings here: Settings object — After Effects Scripting Guide 0.0.1 documentation
And here's a working demo:
(function(thisObj) {
var scriptName = 'Some Script';
var keyName = 'My Checkbox Value';
var win = new Window('palette', scriptName, undefined);
var checkbox = win.add('checkbox', undefined, 'Checkbox');
var btnSaveSettings = win.add('button', undefined, 'Save Settings');
btnSaveSettings.onClick = function () {
var value = checkbox.value.toString();
saveSettings(keyName, value);
saveToDisk();
alert('Settings saved:\nSection Name: ' + scriptName + '\nkeyName: ' + keyName + '\nValue: ' + value);
};
var btnLoadSettings = win.add('button', undefined, 'Load Settings');
btnLoadSettings.onClick = function () {
if (!haveSetting(keyName)) {
throw 'Ups, dont have any settings for "' + keyName + '"';
}
var stringValue = getSetting(keyName);
var value = (stringValue === 'true') ? true : false;
checkbox.value = value;
alert('Settings Loaded:\nSection Name: ' + scriptName + '\nkeyName: ' + keyName + '\nValue: ' + value);
};
win.show();
function getSetting(keyName) {
return app.settings.getSetting(scriptName, keyName);
}
function haveSetting(keyName) {
return app.settings.haveSetting(scriptName, keyName);
}
function saveSettings(keyName, value) {
app.settings.saveSetting(scriptName, keyName, value.toString());
}
function saveToDisk() {
app.preferences.saveToDisk();
}
})();
Copy link to clipboard
Copied
Hi Tomas,
a huge thank you for your reply!
Your demo works like a charm and it made my life easier. Now everything works fine.
Thanks! You are the boss!
This line here:
app.settings.saveSetting("EVLCopy", "passThrough", passThrough.value);
didn't do anything because I didn't know I had to save the settings to disk.
It now saves the settings under ["Settings_EVLCopy"] and not under ["EVLCopy"] as I thought.
These lines here:
- var testing = app.settings.getSetting("AE_OpenGL","Downsample Factor");
- alert(testing);
I was expecting to return an alert with the value 4 but it doesn't work. I think because it searches for ["Settings_AE_OpenGL"], which doesn't exists.
but these lines here work fine now:
- var testing = app.settings.getSetting("EVLCopy","passThrough");
- alert(testing);
So... all good for me!!
Copy link to clipboard
Copied
Well, to get that value, you'd need to check app.preferences object.
(function() {
var sectionName = 'AE_OpenGL';
var keyName = 'Enabled2';
var prefType = PREFType.PREF_Type_MACHINE_SPECIFIC;
/*
There are few PrefTypes. Pick one:
PREF_Type_MACHINE_INDEPENDENT
PREF_Type_MACHINE_INDEPENDENT_COMPOSITION
PREF_Type_MACHINE_INDEPENDENT_OUTPUT
PREF_Type_MACHINE_INDEPENDENT_RENDER
PREF_Type_MACHINE_SPECIFIC
PREF_Type_MACHINE_SPECIFIC_PAINT
PREF_Type_MACHINE_SPECIFIC_TEXT
*/
if (!app.preferences.havePref(sectionName, keyName, prefType)) {
throw 'Cannot get "' + keyName + '" in section "' + sectionName + '" in ' + prefType;
}
var prefsValue = app.preferences.getPrefAsString(sectionName, keyName, prefType);
alert('Value for "' + keyName + '" is ' + prefsValue);
/*
app.preferences has exposes these methods:
deletePref
getPrefAsBool
getPrefAsFloat
getPrefAsLong
getPrefAsString
havePref
reload
savePrefAsBool
savePrefAsFloat
savePrefAsLong
savePrefAsString
saveToDisk
*/
})();
Copy link to clipboard
Copied
Wonderful thanks again!
Copy link to clipboard
Copied
Is there documentation on
app.preferences
object?