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

Convert the ascii color code to hex

Explorer ,
Jun 10, 2020 Jun 10, 2020

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

Screenshot_1.pngexpand imageScreenshot_2.pngexpand image

 

 

 

[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

 

Screenshot_3.pngexpand image

 

 

[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

TOPICS
Error or problem , Expressions , How to , Scripting
1.6K
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
New Here ,
Jun 10, 2020 Jun 10, 2020

Hey, check this Creative Cow thread on the subject. Worked for me.

https://forums.creativecow.net/docs/forums/post.php?forumid=227&postid=36449&univpostid=36449&pview=...

 

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. 🙂

 

 

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 ,
Jun 10, 2020 Jun 10, 2020

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 !

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
New Here ,
Jun 10, 2020 Jun 10, 2020

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).

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 ,
Jun 11, 2020 Jun 11, 2020

Tnx Bro for your attention 

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 ,
Jun 12, 2020 Jun 12, 2020

Isn't there really someone who can help?

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 ,
Jun 20, 2020 Jun 20, 2020
LATEST

someone who can help?

@Tomas_Sinkunas

 

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