Skip to main content
Known Participant
June 10, 2020
Question

Convert the ascii color code to hex

  • June 10, 2020
  • 2 replies
  • 1998 views

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

This topic has been closed for replies.

2 replies

Mahdi_UshAuthor
Known Participant
June 12, 2020

Isn't there really someone who can help?

Mahdi_UshAuthor
Known Participant
June 21, 2020

someone who can help?

@Tomas_Sinkunas

 

Participant
June 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=t

 

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

 

 

Mahdi_UshAuthor
Known Participant
June 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 !

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