Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Color control expression – target own color picker in if statement

  • Color control expression – target own color picker in if statement

    Posted by Jeroen Rommelaars on December 4, 2017 at 8:58 am

    EDIT: I’m silly – I had an expression on the textlayer that already changed the source text if the name of the layer was the default. Silly me.
    Consider this fixed 😉

    Hey guys,

    Im currently linking all kinds of colors to a master layer with several color control effects added to it.
    In the same comp as the master color control, I have several text layers that correspond with the color effects.
    For example, i have a color effect thats called background color, and I also have a text layer called background color.

    With expressions, I made it so that if you put a hexcode into the text layer, the color of the effect changes to that color. Works great.

    What i am trying to achieve now, is that when the name of the text layer is its default name, in this case ‘background color’, the effect takes the color of the effects own color picker.

    My code looks like this:

    txt = comp(“master”).layer(8).text.sourceText;
    if (txt==’background color’){
    thisLayer.effect(“background color”)(“Color”)
    } else {
    c = parseInt(txt,16);
    r = c >> 16;
    g = (c & 0x00ff00) >> 8;
    b = c & 0xff;
    [r,g,b,255]/255}

    The problem is, that when the text layer is its defaul name, it doesnt take the color of the color picker, but rather its original color when I added the effect – always bright red.

    I need to adjust this part of the expression: thisLayer.effect(“background color”)(“Color”)
    to something that points directly at the color picker, but I cant figure it out.

    Anyone knows how to achieve that or can point me in the right direction?

    Cheers!

    txt = comp("master").layer(8).text.sourceText;
    if (txt=='background color'){
    thisLayer.effect("background color")("Color")
    } else {
    c = parseInt(txt,16);
    r = c >> 16;
    g = (c & 0x00ff00) >> 8;
    b = c & 0xff;
    [r,g,b,255]/255}

    Scott Mcgee replied 8 years, 8 months ago 2 Members · 3 Replies
  • 3 Replies
  • Scott Mcgee

    December 4, 2017 at 9:41 am

    Not too sure what’s wrong with yours.

    But I’ve re written it to work for me.

    txt = comp(“master”).layer(8).text.sourceText;
    if(txt == “”){
    effect(“Fill”)(“Color”)
    } else {
    txt = “0x” + thisComp.layer(“Colour”).text.sourceText;
    r = txt >> 16;
    g = (txt & 0x00ff00) >> 8;
    b = txt & 0xff;
    [r,g,b,255]/255
    }

    Altered for you

    txt = thisComp.layer(“Colour”).text.sourceText;
    if(txt == “background color”){
    effect(“background color”)(“Color”)
    } else {
    txt = “0x” + thisComp.layer(“Colour”).text.sourceText;
    r = txt >> 16;
    g = (txt & 0x00ff00) >> 8;
    b = txt & 0xff;
    [r,g,b,255]/255
    }

  • Jeroen Rommelaars

    December 4, 2017 at 11:10 am

    Thanks mate,

    See my EDIT at the top of the post.
    I already had a sourcetext changing expression on the text layer which messed up my expression. A stupid mistake which i spent much too much time in fixing 😛

    Still thanks for the help, though!

  • Scott Mcgee

    December 4, 2017 at 11:17 am

    Haha,

    No i did not spot that.

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