ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Make a slider control layers visibility

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Leigh Harrison
Make a slider control layers visibility
on Jun 22, 2016 at 11:26:39 am

Hey, 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


Return to posts index

Joe Clay
Re: Make a slider control layers visibility
on Jun 22, 2016 at 3:12:19 pm

Make 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.tv


Return to posts index

Leigh Harrison
Re: Make a slider control layers visibility
on Jun 22, 2016 at 3:31:07 pm

Thanks 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


Return to posts index


Joe Clay
Re: Make a slider control layers visibility
on Jun 22, 2016 at 3:43:21 pm

What 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=0

Joe Clay
Workbench.tv


Return to posts index

Leigh Harrison
Re: Make a slider control layers visibility
on Jun 22, 2016 at 3:53:35 pm

Thank you so much Joe, the using Null index method works absolutely perfectly.

Have a great day.

Leigh


Return to posts index

Joe Clay
Re: Make a slider control layers visibility
on Jun 22, 2016 at 3:54:39 pm

No problem! Same to you!

Joe Clay
Workbench.tv


Return to posts index


Matthias Schwarz
Re: Make a slider control layers visibility
on Nov 6, 2017 at 2:28:20 pm

Dear 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


Return to posts index

Joe Clay
Re: Make a slider control layers visibility
on Nov 6, 2017 at 10:56:36 pm

The 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.tv


Return to posts index

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