FORUMS: list search recent posts

Switching Effects on & off by a Checkbox controller

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
John Pritchett
Switching Effects on & off by a Checkbox controller
on Nov 4, 2013 at 12:18:46 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]


Return to posts index

Dan Ebberts
Re: Switching Effects on & off by a Checkbox controller
on Nov 4, 2013 at 2:03:20 am

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

Dan



Return to posts index

John Pritchett
Re: Switching Effects on & off by a Checkbox controller
on Nov 4, 2013 at 3:07:15 am

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

Thanks!


Return to posts index


John Pritchett
Re: Switching Effects on & off by a Checkbox controller
on Nov 4, 2013 at 3:17:40 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


Return to posts index

Dan Ebberts
Re: Switching Effects on & off by a Checkbox controller
on Nov 4, 2013 at 4:15:44 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



Return to posts index

John Pritchett
Re: Switching Effects on & off by a Checkbox controller
on Nov 4, 2013 at 5:48:43 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]


Return to posts index


Paul Roper
Re: Switching Effects on & off by a Checkbox controller
on Nov 4, 2013 at 9:31: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]
}


Return to posts index

Paul Roper
Re: Switching Effects on & off by a Checkbox controller
on Nov 4, 2013 at 9:44:42 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:

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

- Paul


Return to posts index

Kevin Camp
Re: Switching Effects on & off by a Checkbox controller
on Nov 4, 2013 at 11:14:57 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


Return to posts index


John Pritchett
Re: Switching Effects on & off by a Checkbox controller
on Nov 5, 2013 at 3:01:17 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


Return to posts index

Paul Roper
Re: Switching Effects on & off by a Checkbox controller
on Nov 5, 2013 at 2:13:11 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]


Return to posts index

Paul Roper
Re: Switching Effects on & off by a Checkbox controller
on Nov 5, 2013 at 2:19:31 pm

And if you also want a shade controller (I'm guessing it's to control the lightness of the colour) you could simply add a slider whose values go from 1 to 6, call it "Lightness" and add a bit to the end of the script:

Change the .1 and the 1 in the "linear" statement to reflect how bright/dark you want it. The ".value.toFixed(0)" ensures that only 6 levels of brightness can be selected, by rounding the value to 0 decimal places.

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;

lightness=effect("Lightness")("Slider").value.toFixed(0);
lightnessMultiplier= linear(lightness,1,6,.1,1);
[c[0],c[1],c[2],1]*lightnessMultiplier


Return to posts index

John Pritchett
Re: Switching Effects on & off by a Checkbox controller
on Nov 12, 2013 at 9:19:32 pm

OK Dan. Ive been working on this script now for a few days with no luck.
Is there any chance I can send you my AE project file? This may give you a better idea of what I am trying to achieve.
Many Thanks


Return to posts index

Dan Ebberts
Re: Switching Effects on & off by a Checkbox controller
on Nov 13, 2013 at 7:25:06 pm

If you want to do that, I'll take a look at it. I've got a couple of big projects going, so I won't have a lot of time to fiddle with it.

Dan



Return to posts index

John Pritchett
Re: Switching Effects on & off by a Checkbox controller
on Nov 18, 2013 at 3:55:59 am

Hi Dan,
Sorry for the slow reply. I have been on and off this job.
It would be great if you could help me out. There is no urgent rush.
How to I get you the job file?
Thanks


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]