Forums › Adobe After Effects Expressions › Make a slider control layers visibility
Make a slider control layers visibility
Leigh Harrison
June 22, 2016 at 11:26 amHey, I have a comp with 4 pre comps inside, each pre-comp is a different view of a character (front, back, left, right). At the minute I have a adjustment layer with 4 sliders, each controlling the opacity of the individual layers to enable a kind of on/off switch by having 4 keyframes, 3 at 0 (0% opacity) and 1 and 1 (100% opacity, I changed the edit value setting on the slider effect to 1 and added *100 to get the value up to 100%). So this works absolutely fine, but I was wondering if there was an expression to streamline my workflow, from 4 keyframes to 1. Maybe like a if\else option or something to let 1 keyframe drive all the values. I don’t expressions well enough but something like if I had another slider controller that if I typed in a value it would pass through and work out the opacities throughout, ultimately perhaps assigning 1 to drive layers 1 opacity, 2 for layer 2, 3 for 3 etc.
So, crudley put something like;if thisComp.layer(“View Controller”).effect(“Front View”)(“Slider”) 1) else 0;
There’s probably more to it than that but any pointers would be appreciated?
Leigh
Joe Clay
June 22, 2016 at 3:12 pmMake a new null with a slider on it. Then add this expression to the layers you want to use in there. And keyframe it with the indexes you want to turn on. Be aware that you can’t put any layers in between or you will mess it up. There are some fixes for that if you need to add stuff in between.
You can also use a layer selector. That should work even if you put things in between I believe. I’ll check it and post up an AEP with the different options.
pos = thisComp.layer("Null 1").effect("Position")("Slider");
if(pos == index) { 100 } else { 0 };Joe Clay
Workbench.tvLeigh Harrison
June 22, 2016 at 3:31 pmThanks Joe, appreciate you taking the time to reply and look forward to your posted project file.
I can’t seem to get this working at present, but hopefully you can shed some light on it with your upload.
It’s this particular part of your instructions that I’m unclear on I’m afraid;“And keyframe it with the indexes you want to turn on”
Thanks again,
Leigh
Joe Clay
June 22, 2016 at 3:43 pmWhat I meant by keyframing the null with the indexes, is that when you set up the null and the slider, the slider is keyframed to the index of the layer you want to be on. So if you want layer 3 to be on, you set it to 3. In the first version I sent over, you can’t put layers above your layers because their indexes will change.
If you use the “using null index” comp, the script subtracts out the controller null’s index so that the layer directly under the null is always 1 on the slider. That way you can just keep the group together.
Unfortunately I forgot that, for some stupid reason, you can’t keyframe the layer control. If you could, then you could just keyframe the layer you want to be visible. I’ve done some plugin programming, so if it’s possible maybe I can make a quick plugin that is basically the same layer control just keyframeable, haha.
Anyway, here’s the aep:
https://www.dropbox.com/s/al0vyje2zji1cfn/SwitchingOpacity.aep?dl=0Joe Clay
Workbench.tvLeigh Harrison
June 22, 2016 at 3:53 pmThank you so much Joe, the using Null index method works absolutely perfectly.
Have a great day.
Leigh
Joe Clay
June 22, 2016 at 3:54 pmNo problem! Same to you!
Joe Clay
Workbench.tvMatthias Schwarz
November 6, 2017 at 2:28 pmDear Joe,
could you please upload a CS6-version of this AE-project for me(your CC-Version doesn´t work for me)? I´m very interested in understanding this workflow because I´m new in expressions and I hope to understand it an wanna use this technique for some of my projects.
Hope you read this,yours, Matthias
Joe Clay
November 6, 2017 at 10:56 pmThe setup is a Null with a layer expression control on it. Then the layers you want to turn on/off.
Opacity has this expression on it:
selected = thisComp.layer("Null 1").effect("Layer Control")("Layer");
if(selected.index == index) { 100 } else { 0 };This version works if you keep your layers that you want to switch directly under the null, that way if you put layers above them, they’re not all going to change when their absolute index value changes. This way they’re all relative to the null. I’d go with this one.
main = thisComp.layer(“Null 1”).index;
pos = thisComp.layer(“Null 1”).effect(“Position”)(“Slider”);
if(pos == index-main) { 100 } else { 0 };Hopefully that helps. After the index is figured out, all it does is look at the slider on that null layer and if the index of the layer is the same as the slider, it sets opacity to 100%. If you have another question, feel free to ask.
Joe Clay
Workbench.tvBrian Clark
July 16, 2018 at 11:29 pmHi Joe,
Thanks for posting about this! It has come in handy for a recent project. I’m trying to do exactly as you
have suggested in this thread, except instead of the previous layer turning off as the slider value increases,
I need the previous layer to stay active/visible. So that when the slider is set to 0, there are no visible layers,
and a slider value of 4 would show layers 1-4.I tried my best to convey that. Please let me know if you have any questions. Thank you!
Joe Clay
July 17, 2018 at 2:27 amHi Brian!
You’d just need to pick whip your slider and set it to a variable so you end up with something like this:
t = thisComp.layer(“Controller”).effect(“Slider”)(“Slider”);
And then do:
if(index < t + 1) { 100 } else { 0 }
This assumes that your layers start at the top of the comp. if that doesn’t make sense let me know!
Joe Clay
Workbench.tv
Log in to reply.