Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Working with AE Preference settings

Engaged ,
May 20, 2018 May 20, 2018

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?

TOPICS
Scripting
3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , May 20, 2018 May 20, 2018

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

...
Translate
Advocate ,
May 20, 2018 May 20, 2018

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();

    }

})();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 20, 2018 May 20, 2018

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:

  1. var testing = app.settings.getSetting("AE_OpenGL","Downsample Factor"); 
  2.           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.

Capture.PNG

but these lines here work fine now:

  1. var testing = app.settings.getSetting("EVLCopy","passThrough"); 
  2.           alert(testing); 

So... all good for me!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 21, 2018 May 21, 2018

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

    */

})();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 21, 2018 May 21, 2018

Wonderful thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 10, 2019 Jan 10, 2019
LATEST

Is there documentation on

app.preferences

object?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines