Copy link to clipboard
Copied
Hello
I've been confused for a few days and I can't make a logical code equation to read the existing color code.
I want to know how to convert this output to Hex color code
[Project]
We want to be able to call the names and colors code in the following address with script code
AE => Edit => Preferences => Labels => Label Colors
[My Code]
var Color = app.preferences.getPrefAsString("Label Preference Color Section 5", "Label Color ID 2 # 1", PREFType.PREF_Type_MACHINE_INDEPENDENT);
var NameColor = app.preferences.getPrefAsString("Label Preference Text Section 7", "Label Text ID 2 # 1", PREFType.PREF_Type_MACHINE_INDEPENDENT);
[Problem]
Color = ��
NameColor = Red
[Want !]
How Can Read Color Code whit Hex
[efforts]
var aaColor = app.preferences.getPrefAsString("Label Preference Color Section 5", "Label Color ID 2 # 1", PREFType.PREF_Type_MACHINE_INDEPENDENT);
var aaNameColor = app.preferences.getPrefAsString("Label Preference Text Section 7", "Label Text ID 2 # 1", PREFType.PREF_Type_MACHINE_INDEPENDENT);
String.prototype.hexEncode = function(){
var hex, i;
var result = "";
for (i=0; i<this.length; i++) {
hex = this.charCodeAt(i).toString(16);
result += ("000"+hex).slice(-4);
}
return result
}
var aaHex = aaColor.hexEncode();
I definitely believe it's possible!
Please tell if someone knows the solution!
Tnx Alot
Copy link to clipboard
Copied
Hey, check this Creative Cow thread on the subject. Worked for me.
The code from the thread (I don't take any credit for it...):
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;
});
}
To do it the other way around, though - saving a new color label to the prefs - I have no idea. If anyone else knows the solution, it would be greatly appreciated. 🙂
Copy link to clipboard
Copied
Thanks for your attention and reply!
Unfortunately, I had previously checked this code and your link, and since I didn't get the result and this code didn't work, I created this post!
This function you wrote can't do anything special here .
Just test it to make sure it's in the After Effects and be aware of the results
File => Scripts => Open Script Editor
and check Result !
Copy link to clipboard
Copied
Did you make sure to not use the "getPrefAsString" function but rather go into the prefs text file itself to get the label color? "getPrefAsString" doesn't seem to work in this particular case because in the text file everything within quotes is considered to be the string to retrieve - however the label colors themselves have these quotes within their code, which kind of messes with extracting the data (at last to my humble understanding of it).
Copy link to clipboard
Copied
Tnx Bro for your attention
Copy link to clipboard
Copied
Isn't there really someone who can help?
Copy link to clipboard
Copied
someone who can help?
@Tomas_Sinkunas