Highlighted

Convert the ascii color code to hex

Community Beginner ,
Jun 10, 2020

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

Screenshot_1.pngScreenshot_2.png

 

 

 

[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.png

 

 

[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

Views

374

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Convert the ascii color code to hex

Community Beginner ,
Jun 10, 2020

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

Screenshot_1.pngScreenshot_2.png

 

 

 

[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.png

 

 

[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

Views

375

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 10, 2020 0
New Here ,
Jun 10, 2020

Copy link to clipboard

Copied

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

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 10, 2020 0
Community Beginner ,
Jun 10, 2020

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 !

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 10, 2020 0
New Here ,
Jun 10, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 10, 2020 1
Community Beginner ,
Jun 11, 2020

Copy link to clipboard

Copied

Tnx Bro for your attention 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 11, 2020 0
Community Beginner ,
Jun 12, 2020

Copy link to clipboard

Copied

Isn't there really someone who can help?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2020 0
Community Beginner ,
Jun 20, 2020

Copy link to clipboard

Copied

someone who can help?

@Tomas_Sinkunas

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 20, 2020 0