Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Hex Code from text?

  • Hex Code from text?

  • Chris Street

    September 18, 2017 at 10:34 am

    Hi, I have a query.

    I have a text layer which contains a hex value. I also have a Colour Control effect applied to a Null object.

    I would like to set the colour of the Colour Control to the value which the text layer contains, using an expression

    So, for example, if the value “ff0000” was written inside the text layer, the Colour Control effect would use that value and create a red colour.

    Is there a way this can be achieved?

    Many thanks!

  • Scott McGee

    September 18, 2017 at 11:38 am

    Dan Ebberts posted this a while back for someone else

    hexColor = 0xfbd142;
    r = (hexColor >> 16)/255;
    g = ((hexColor & 0x00ff00) >> 8)/255;
    b = (hexColor & 0xff)/255;
    hsl = rgbToHsl([r,g,b,1]);

    You could set up your “Text” layer (source text) add this to the expression

    “0x” + text.sourceText;

    Then when you copy and paste the hex code it will automatically add the 0x at front.

    Then the above expression change to this.

    hexColor = thisComp.layer(“Text”).text.sourceText;
    r = (hexColor >> 16)/255;
    g = ((hexColor & 0x00ff00) >> 8)/255;
    b = (hexColor & 0xff)/255;
    hsl = rgbToHsl([r,g,b,1]);

    That should work for you.

  • Chris Street

    September 18, 2017 at 12:51 pm

    Hi, thanks for your help but I’m not sure if I’ve done this correctly.

    The initial hex colour in the text layer is “ff0000” (red) but after implementing the code as below, the resultant colour ends up being a hex value of #2C3C7A (a luminous green).

    Have I done anything wrong here?

    Thanks for the assistance!

    hex_edited is the text layer (initally written as ff0000):

    "0x" + thisComp.layer("hex_edited").text.sourceText;

    Colour Control Expression:

    hexColor = thisComp.layer("hex_edited").text.sourceText;
    r = (hexColor >> 16)/255;
    g = ((hexColor & 0x00ff00) >> 8)/255;
    b = (hexColor & 0xff)/255;
    hsl = rgbToHsl([r,g,b,1]);

  • Dan Ebberts

    September 18, 2017 at 12:59 pm

    Try this:

    txt = thisComp.layer(“Text”).text.sourceText;
    c = parseInt(txt,16);
    r = c >> 16;
    g = (c & 0x00ff00) >> 8;
    b = c & 0xff;
    [r,g,b,255]/255

    Dan

  • Chris Street

    September 18, 2017 at 1:03 pm

    That’s absolutely fantastic, works perfectly! Thank you so much 😀

  • Scott McGee

    September 26, 2017 at 10:25 am

    Bizzarely, as I didn’t test it and now need to use this…I got a luminous green as well, but with Dan’s new expression I got pink.

    txt = 0x0000ff;
    r = txt >> 16;
    g = (txt & 0x00ff00) >> 8;
    b = txt & 0xff;
    [r,g,b,255]/255

    This strangely works for me.

    Dan if you have a minute, is there a reason why the three expressions (Similar) although people have responded that they work, it reacts differently for others…I am scratching my head here.

    I only took a stab in the dark by removing the c and just replacing it all with txt and it worked first time.

    Bizarre.

  • gray wilcox

    May 1, 2021 at 1:53 am

    I’m using a .csv in my project (not in my actual comp) and i’m attempting to use Hex code from the .csv to drive my color control expression.

    compName = thisComp.name;
    hexColor = footage(“players_cards – one_team.csv”).dataValue([37,compName]);
    r = (hexColor >> 16)/255;
    g = ((hexColor & 0x00ff00) >> 8)/255;
    b = (hexColor & 0xff)/255;
    hsl = rgbToHsl([r,g,b,1]);

    the idea being the comp is labeled “0” and when i make duplicates, it will increment up and make new versions of the same player card, with new data from the .csv file.

  • gray wilcox

    May 1, 2021 at 2:21 am

    so i fixed my issue:

    my .csv had HEX values with a # in front. i removed the #’s leaving only the digits, and everything worked.

Viewing 1 - 8 of 8 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy