Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression control for only the hue of a fill in a shape layer

  • Expression control for only the hue of a fill in a shape layer

    Posted by Steve Miller on March 17, 2016 at 2:07 am

    Hi All,

    Thanks to Mr. Soyka’s really cool hack of the After Effects editable text templates for Premiere, I’ve been able to add fields to change opacity and scaling to my templates.
    So, for anyone out there, Mr. Soyka included 🙂
    I’ve been trying to figure out how he/you changed the color using a single value and while I was trying to figure it out I was able to see how to extract the hsl values from rgb with the AE expression, but for the life of me I cannot get a suitable expression completed to have the text input control the hue value of the fill of a rectangle.

    When I pickwhip the color of the fill in the rectangle
    it comes back with:

    content(“Rectangle 1”).content(“Fill 1”).color

    but when I try to insert that value into a variable like I’ve seen in so many of the tutorials I’ve gone through like this:

    rgb =content(“Rectangle 1”).content(“Fill 1”).color;

    hsl = rgbToHsl(rgb)

    I get an error saying that the expression result should be dimension 4 not 1 – which I understand, [h,s,l,a], but in all the different tutorials out there, this is how it was done.

    Eventually, I’m wanting to use the parseFloat expression to take a numerical value from a hidden text box to change the value of the color of the text box.

    Any ideas?

    Thanks!

    *steve

    Rick Lavon replied 10 years, 1 month ago 3 Members · 13 Replies
  • 13 Replies
  • Dan Ebberts

    March 17, 2016 at 5:55 am

    >I get an error saying that the expression result should be dimension 4 not 1

    Where are you applying the expression? I just tried it on another color property and it works for me.

    Dan

  • Steve Miller

    March 17, 2016 at 4:59 pm

    I’m doing this in the color property of the rectangle’s fill.

  • Dan Ebberts

    March 17, 2016 at 5:13 pm

    Strange. If I do this:

    1. New comp
    2. New rectangle shape
    3. Add this expression to fill color:

    rgb =content(“Rectangle 1”).content(“Fill 1”).color;
    hsl = rgbToHsl(rgb)

    I get no error, and the color turns olive green. I’m not sure why it doesn’t work for you.

    This also works:

    hsl = rgbToHsl(value)

    Dan

  • Steve Miller

    March 18, 2016 at 5:00 pm

    Dan,

    Yeah, that’s the strange thing. When I created a new project and input the expression again, it all worked fine. I guess I might of had a typo or something that I didn’t see?

    Anyway, here is the final expression on the fill color of a shape layer’s rectangle which allows a hidden text box control to change the hue of the fill. The reason for this is that with the text template feature in After Effects, I can create a template which the fill color can be changed in Premiere on the fly.

    rgb = content(“Rectangle 1”).content(“Fill 1”).color;
    n = parseFloat(thisComp.layer(“[Test]”).text.sourceText);
    hsl = rgbToHsl(rgb);
    changeHsl = [(n/360) , 1 , hsl[2] , hsl[3]];
    hslToRgb(changeHsl);

    Thanks for the help!

    *steve

  • Rick Lavon

    March 24, 2016 at 5:19 pm

    Hi-

    I am trying your expression but I keep getting an error that the layer “Test” is missing. Is Test the name of your shape layer?..I changed it but nothing changes.
    Also, in the text layer, are you using several expression color controls or the fill control? I guess what I;m asking is what are hsl 1,2 and 3?

  • Dan Ebberts

    March 24, 2016 at 5:55 pm

    [Test] (including the brackets) would be the name of the text layer where he as specified the hue, with a value between 0 and 360.

    Dan

  • Steve Miller

    March 24, 2016 at 6:37 pm

    Rick, this is my final script that’s working for me:

    {for changing a color based on the hue value (0-360), saturation (0-100) and lightness (0-100) from a hidden text layers
    Apply this to the rectangle fill}

    rgb = content("Rectangle 1").content("Fill 1").color;
    hue = parseFloat(thisComp.layer("[Hue]").text.sourceText);
    saturation = parseFloat(thisComp.layer("[Saturation]").text.sourceText);
    lightness = parseFloat(thisComp.layer("[Lightness]").text.sourceText);
    hsl = rgbToHsl(rgb);
    changeHsl = [(hue/360) , (saturation/100) , (lightness/100] , hsl[3]];
    hslToRgb(changeHsl);

  • Rick Lavon

    March 24, 2016 at 6:58 pm

    can you give an example of what you type into the text layer to achieve this?

  • Steve Miller

    March 24, 2016 at 7:04 pm

    the text layer names are [Hue], [Saturation] and [Lightness]
    after you set up the expression, change hue from 0-360, saturation from 0-100, and lightness from 0-100

  • Rick Lavon

    March 24, 2016 at 7:29 pm

    Sorry to be bugging you..There is an error on line 6-
    Expected: ).

Page 1 of 2

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