ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Scripting: Retrieving Label Color from Preferences

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jay Brown
Scripting: Retrieving Label Color from Preferences
on Jul 26, 2017 at 9:43:46 pm
Last Edited By Jay Brown on Jul 28, 2017 at 1:49:47 am

I've been trying to figure this out the last couple of days and just can't get by it.
I'm trying to get the assigned preference Label Colors from the preference text file: "Adobe After Effects 14.2 Prefs-indep-general.txt"

Here is a simplified version of what I got:
var labelColor1 = app.preferences.getPrefAsString("Label Preference Color Section 5", "Label Color ID 2 # 1", PREFType.PREF_Type_MACHINE_INDEPENDENT);
alert(labelColor1);


It is returning ��88 when it should be retuning FFB5"88"
Maybe it has something to do with the way it is being encoded when converted to a string or what.

Anyways, any help would be greatly appreciated! 😃

Thanks,
-Jay


Return to posts index

Jay Brown
Re: Scripting: Retrieving Label Color from Preferences
on Jul 28, 2017 at 2:01:06 am

I ran a few tests and it seems as though getPrefAsString() imports anything surrounded in quotes fine, but struggles with characters outside of quotes. Sort of makes sense, in that whatever is in quotes is considered a string, not sure why it still retrieves some additional data though.

Still looking for a solution. Not sure if savePrefAsString() could be used to add quotes to the existing pref text document or something like that, and then try to retrieve the string again? TBD!


Return to posts index

Xavier Gomez
Re: Scripting: Retrieving Label Color from Preferences
on Jul 29, 2017 at 9:10:37 am

You could try getPrefAsLong(), which should produce a number.
Most probably an integer in the range 0 - (255*255*255-1).
Then you should convert that number to an array [R, G, B], all entries in the range 0-255, then divide all entries by 255 to get an array [r, g, b], entries in the range [0,1], which is what After Effects uses.
I havent tried, but worth trying.

Xavier.


Return to posts index


Jay Brown
Re: Scripting: Retrieving Label Color from Preferences
on Aug 1, 2017 at 11:08:44 pm

Ahhh, okay I'll give that a try
The one time I need getPrefAsString and it only doesn't work for this specific setting x_x


Return to posts index

Xavier Gomez
Re: Scripting: Retrieving Label Color from Preferences
on Aug 6, 2017 at 1:12:33 pm

Sorry, i didnt check the thread much after writing to it.
getPrefAslong doesnt work and, as you already said, getPrefAsString produces a string that is hardly usable.

It seems that one can recover the actual hex color code from the string as written in the prefs file by converting everything that is in between quotes like this:

function prefCodeToHexCode(str){
return str.replace(/"([^"]+)"/g, function(u, code){
var result = "";
for (var i=0; i return result;
});
};

For instance, prefCodeToHexCode('FFB5"88"') produces the string 'FFB53838', which is correct.
Now, getPrefAsString() omits the quotes, so we are lost. It does seem that you'll have to get the pref by actually reading the prefs file (this requires to know the pref file path, then extract the correct part in the pref file, etc, bit tedious), then use a function as above to get the hex code for the color.

I dont have a clue why the color is encoded that way in the prefs file, nor how should look like the converse function, hexCodeToPrefCode.

Xavier


Return to posts index

Xavier Gomez
Re: Scripting: Retrieving Label Color from Preferences
on Aug 6, 2017 at 1:15:52 pm

The code failed to be written correctly, and i can't edit, so once again:

function prefCodeToHexCode(str){
return str.replace(/"([^"]+)"/g, function(u, code){
var result = "";
for (var i=0; i<code.length; i++){result += code.charCodeAt(i).toString(16);};
return result;
});
};


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]