Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Switching Effects on & off by a Checkbox controller

  • Switching Effects on & off by a Checkbox controller

    Posted by John Pritchett on November 4, 2013 at 12:18 am

    Hi,
    Im a little stumped here. I need to turn on and off an effect using a checkbox control.
    I have searched other ideas where they all suggest controlling an element of the effect such as opacity.
    This wont work in my case.
    The effect is Fill, where I have 6 Fill effects on one layer. Each Fill effect has a script of its own. So I only want one of the effects on at any one time.
    Is there a way to turn on or off the Fill effect?
    I have included the script which I have on each effect.
    Many thanks in advance!!!!

    This is on the "Red" Fill effect:
    s = thisComp.layer("Colour Controls").effect("STRAP Colour")("Slider")
    colors = [[255,255,255],
    [179,32,52],
    [232,73,27],
    [239,125,0],
    [252,192,67],
    [255,229,150]];
    idx = Math.max(Math.min(colors.length-1,Math.round(s)-1),0);
    c = colors[idx]/255;
    [c[0],c[1],c[2],1]

    This is on the "Green" Fill effect. There are 6 Fill effects on the one layer.
    s = thisComp.layer("Colour Controls").effect("STRAP Colour")("Slider")
    colors = [[255,255,255],
    [0,104,51],
    [19,165,56],
    [162,199,59],
    [221,223,75],
    [255,242,101]];
    idx = Math.max(Math.min(colors.length-1,Math.round(s)-1),0);
    c = colors[idx]/255;
    [c[0],c[1],c[2],1]

    John Pritchett replied 12 years, 5 months ago 4 Members · 14 Replies
  • 14 Replies
  • Dan Ebberts

    November 4, 2013 at 2:03 am

    Could you do it with a Color Overlay Layer Style instead of Fill and control the opacity of that?

    Dan

  • John Pritchett

    November 4, 2013 at 3:07 am

    Gees Your good!
    Why didn’t I think of that…..

    Thanks!

  • John Pritchett

    November 4, 2013 at 3:17 am

    Actually Dan, after replying to say that using a colour overlay would work, it won’t, as you can only apply one layer style to a layer. Where as you can apply as many fill effects as needed…
    Any other thoughts???

    Thanks

  • Dan Ebberts

    November 4, 2013 at 4:15 am

    This might be a long shot, but it might be worth a try. Create a different layer-sized mask for each Fill and select it with the effect’s Fill Mask dropdown. That seems to let the Fill’s opacity work as you’d expect.

    Dan

  • John Pritchett

    November 4, 2013 at 5:48 am

    OK. Thanks Dan this works OK for the solid layers, but not the Text layers…. When I apply this method, the entire layer gets filled….
    I have added below the script to change the colour of the fill.
    Basically I have 6 colour ways, each containing 6 shades of that colour.
    I currently have a controller choosing what shade gets selected in the Fill.
    Is there a way to add another controller to or check box to enable or disable scripts?
    This would be so I can take the approach of having one Fill effect with a script for each colour (6 colours x 6 shades), instead of 6 Fill effects with less complex scripts…
    Does this make sense???
    Much Appreciated.

    s = thisComp.layer("Colour Controls").effect("NAME Colour")("Slider");
    colors = [[255,255,255],
    [179,32,52],
    [232,73,27],
    [239,125,0],
    [252,192,67],
    [255,229,150]];
    idx = Math.max(Math.min(colors.length-1,Math.round(s)-1),0);
    c = colors[idx]/255;
    [c[0],c[1],c[2],1]

  • Paul Roper

    November 4, 2013 at 9:31 am

    You could add a Checkbox Control (I’ve called it “Script on”) to each layer, and change your script to this (this sets the colour to black [0,0,0,0] if the checkbox is off. The alpha control does nothing in the fill effect):

    if (effect("Script on")("Checkbox") == 1)
    {
    s = thisComp.layer("Colour Controls").effect("NAME Colour")("Slider");
    colors = [[255,255,255], [179,32,52], [232,73,27], [239,125,0], [252,192,67], [255,229,150]];
    idx = Math.max(Math.min(colors.length-1,Math.round(s)-1),0);
    c = colors[idx]/255;
    [c[0],c[1],c[2],1]
    }
    else
    {
    [0,0,0,0]
    }

  • Paul Roper

    November 4, 2013 at 9:44 am

    Instead of a checkbox, you could add an “if it’s a text layer, then do this, if it’s a fill layer, then do that” kind of expression. This page talks about getting the type of layer:

    https://www.redefinery.com/ae/fundamentals/layers/#layers_checkiftype

    – Paul

  • Kevin Camp

    November 4, 2013 at 11:14 pm

    i think i’d definitely put this into one expression on one fill layer…

    instead of color = [rgb-array-for-reds]

    red = [rgb-array-for-red]
    green = [rgb-array-for-green]
    etc…

    then use something to control which rgb array is used. if or elseif statements linked to a slider value would work well if you need to keyframe the slider to change…

    layer markers or layer marker comments could be another way to drive the selection.

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • John Pritchett

    November 5, 2013 at 3:01 am

    OK. Kevin, I think you might have the answer.
    But I really have no idea how to implement.
    I guess I need 2 controllers.
    – The main controller to determine what colour to use. (red, green, turquise, blue, purple or magenta)
    – The shade controller to determine what shade of the above colours to use. (shade 1 to 6)
    I would prefer to have the colour control to be 6 check boxes to clearly label each colour, rather than a slider with a number relating to a colour….

    So I would be looking for:
    If red checkbox is on, apply-

    s = thisComp.layer(“Colour Controls”).effect(“Colour”)(“Slider”);
    colors = [[255,255,255],
    [179,32,52],
    [232,73,27],
    [239,125,0],
    [252,192,67],
    [255,229,150]];
    idx = Math.max(Math.min(colors.length-1,Math.round(s)-1),0);
    c = colors[idx]/255;
    [c[0],c[1],c[2],1]

    If green checkbox is on, apply-

    s = thisComp.layer(“Colour Controls”).effect(“Colour”)(“Slider”);
    colors = [[255,255,255],
    [0,104,51],
    [19,165,56],
    [162,199,59],
    [221,223,75],
    [255,242,101]];
    idx = Math.max(Math.min(colors.length-1,Math.round(s)-1),0);
    c = colors[idx]/255;
    [c[0],c[1],c[2],1]

    etc etc for all shades.

    Any ideas?
    Many thanks

  • Paul Roper

    November 5, 2013 at 2:13 pm

    A potential problem with checkboxes is that they are not mutually exclusive – what happens if more than one checkbox is on? Or if no checkboxes are on? That’s why ‘radio buttons’ were invented for interfaces.

    But having said that, here’s an adaptation of your expression using checkboxes. The first line makes sure that if none of the “if” conditions are satisfied, it will default to 0, white. The colour will be whatever the last “on” checkbox is (AE evaluates all the “if” statements, so whatever’s last will be the result).

    idx=0;
    if (effect("reddish")("Checkbox") ==1) { idx = 1};
    if (effect("dark orange")("Checkbox") ==1) { idx = 2};
    if (effect("light orange")("Checkbox") ==1) { idx = 3};
    if (effect("yellow")("Checkbox") ==1) { idx = 4};
    if (effect("pale yellow")("Checkbox") ==1) { idx = 5};

    colors = [[255,255,255],
    [179,32,52],
    [232,73,27],
    [239,125,0],
    [252,192,67],
    [255,229,150]];
    c = colors[idx]/255;
    [c[0],c[1],c[2],1]

Page 1 of 2

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