Copy link to clipboard
Copied
What kind of data are label colors being saved as in prefs ?
I know this was discussed in a post but can't find the exact post....
Thanks
Alan.
"Label Color ID 2 # 1" = FFB60505
"Label Color ID 2 # 10" = FF8E","9A
"Label Color ID 2 # 11" = FFC8"~"0C
"Label Color ID 2 # 12" = FF7F"E*"
Copy link to clipboard
Copied
I would assume string given that prefs can be saved or retrieved via these methods:
app.preferences
.deletePref()
.getPrefAsBool()
.getPrefAsFloat()
.getPrefAsLong()
.getPrefAsString()
.havePref()
.reload()
.savePrefAsBool()
.savePrefAsFloat()
.savePrefAsLong()
.savePrefAsString()
.saveToDisk()
Copy link to clipboard
Copied
Thanks David, but I am trying to figure out how the colours are represented in these strings, don't recognise the data format...
thanks.
Copy link to clipboard
Copied
Ah, gotcha. They look encoded somehow, instead of hex values. I was getting strange results retrieving them with getPrefAsString().
Copy link to clipboard
Copied
Hey David, was chatting with Kevin Schires...
It's preceeded with FF, then a Hex. Some characters in quotes need to be converted to URL encoding - but there is still some
funky stuff going on with them, going to experiment a bit more with them tomorrow.
Copy link to clipboard
Copied
Good to know. If I get some free time, I'll try some more tests.
Copy link to clipboard
Copied
David, got to the bottom of this...
function hex2Ascii(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
So it is saving the values in Ascii format characters.
So using RGB-HEX-ASCII and vice vearsa solves the issue.
I can now recode a couple of scripts to access the settings -
(when I have a minute to myself that is !)
Copy link to clipboard
Copied
Thanks for this Alan - very useful to know. I too was puzzled by this!
Anyone know the reason for this encoding, when other strings are human readable?
Christian
Copy link to clipboard
Copied
Nicely done Alan. Great info to have. Not sure of the reason behind ASCII instead of a straight forward HEX, but there are many odd things behind the coding doors of Adobe.
Copy link to clipboard
Copied
Sorry for upping an old thread.
Alan, have you succeed with the whole decoding stuff and made it readable?
Copy link to clipboard
Copied
Hi Alex... RGB-HEX-ASCII was the conversion process... not at desk this wk but if you google a couple of functions to translate the characters...2 steps. tested it a long time ago with a color picker and it worked.
Copy link to clipboard
Copied
function changeColPref(num,r,g,b){
var sect = "Label Preference Color Section 5";
var key = "Label Color ID 2 # " + num.toString();
var thePref = app.preferences.getPrefAsString(sect,key);
//for reading
function hexToRgb(str) {
if ( /^#([0-9a-f]{3}|[0-9a-f]{6})$/ig.test(str) ) {
var hex = str.substr(1);
hex = hex.length == 3 ? hex.replace(/(.)/g, '$1$1') : hex;
var rgb = parseInt(hex, 16);
return 'rgb(' + [(rgb >> 16) & 255, (rgb >> 8) & 255, rgb
& 255].join(',') + ')';
}
}
function ascii2hex(str) {
var arr = [];
for (var i = 0, l = str.length; i < l; i ++) {
var hex = Number(str.charCodeAt(i)).toString(16);
arr.push(hex);
}
return arr.join('');
}
//for writing
function hex2Ascii(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
function rgbToHex(r,g,b) {
var out = '';
//Adobe expects 4Chars, first one is always...
for (var i = 0; i < 3; ++i) {
var n = typeof arguments == 'number' ? arguments :
parseInt(arguments);
if (isNaN(n) || n < 0 || n > 255) {
return false;
}
//out+=" %" // so we decode %22 %56 %99 - spaces between.
out += (n < 16 ? '0' : '') + n.toString(16);
}
alert(out);
return "FF"+out; //#171717
}
var newCol = rgbToHex(r,g,b);
var newColAscii = hex2Ascii(newCol);
app.preferences.savePrefAsString(sect,key,newColAscii);
app.preferences.saveToDisk();
app.preferences.reload();
}//close change pref.
changeColPref(1,5,199,252);
This is the code that I used a few years ago, so have not looked at it since... perhaps you can muddle through it and see if it works with CC . . .
Copy link to clipboard
Copied
Alan, thank you very much!
To make things work in newer version we need only to add PREFType.PREF_Type_MACHINE_INDEPENDENT
To:
var thePref = app.preferences.getPrefAsString(sect,key, PREFType.PREF_Type_MACHINE_INDEPENDENT);
and
app.preferences.savePrefAsString(sect,key,newColAscii, PREFType.PREF_Type_MACHINE_INDEPENDENT);
Copy link to clipboard
Copied
Well, yeah.
It doesn't work in AE since CC (maybe CC14 or CC12) versions because
app.preferences.getPrefAsString(sect,key);
is broken there and it gives corrupted values, so you can write values, but can't read them.
Copy link to clipboard
Copied
Has anyone found a workaround for this? I'm getting the "could not convert Unicode characters" error when calling app.preferences.getPrefAsString() on color label values.
Copy link to clipboard
Copied
Unfortunately, there is no workaround so far.
Copy link to clipboard
Copied
There is a nasty workaround - you have to read prefs file as a text document, parse it and get those values as strings. It's stupid, but that's the only way around that error.
Copy link to clipboard
Copied
This is what I got to work with AE16.1 (Apr 19)
function asciiToRGB(str) {
var arr = [];
for (var i = 1, l = str.length; i < l; i ++) {
var hex = Number(str.charCodeAt(i)).toString(16);
arr.push(parseInt(hex, 16)/65533);
}
return arr;
}
var colours = [];
for (var i = 1; i <= 16; i++){
var sect = "Label Preference Color Section 5";
var key = "Label Color ID 2 # " + i.toString();
var prefType = PREFType.PREF_Type_MACHINE_INDEPENDENT
var thePref = app.preferences.getPrefAsString(sect,key, prefType);
colours[i-1] = asciiToRGB(thePref);
}
This is just for reading the label colours, I haven't worked out the writing side, but I'm guessing it will just be the reverse.
Copy link to clipboard
Copied
Ahh, close, but no biscuit. It works for some of the colours, but not for others.
@Adobe, please tell us how the label colours are encoded in the prefs, or make the RGB label values accessible to scripting somehow. It's so frustrating.
Copy link to clipboard
Copied
Be careful when reading label colors from preferences with app.preferences.getPrefAsString(sect, key, prefType) as AE might (and most likely) throw error Unable to parse Unicode Character (or something similar). I'm saying this from experience - I am getting this error all the time on Mac.
What is that 65533 value you are using?
As a side note, Label colors are stored in a mixed ASCII and HEX format. Values in quotes represent printable ASCII characters (32 to 127 in decimal, or 20 to 7E in hex) from the Standard ASCII table. Other values, that fall into Extended ASCII table, are left as hex values.
Copy link to clipboard
Copied
I have posted my solution for this here:
https://github.com/GoodBoyNinja/Get-Layers-Label-Colors-using-CEP