Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression Layer Control On/Off Switch

  • Expression Layer Control On/Off Switch

    Posted by Fabian Bosman on May 23, 2013 at 12:39 pm

    Hi,

    I’m working on a project for a tv station, I’m creating a template with different options that the user can choose.
    For example you can change the day, change the time, the programs..ect

    Explaination what I’m doing:
    What I want is that the user can change all this settings in the main comp by using expression controls wich are linked to the settings in the precomp.

    My Question
    I saw the expression layer control option, is it possible to select the layer that you want in the expression Layer control, and only the selected layer will be visible?
    So that if you select the layer that you want, only that layer will be visible or only the layer its opacity is 100%.

    I know, very long explaination but I hope you will understand it. here is an exmaple.
    https://images.creativecow.net/259235/layercontrol.jpg

    Hope someone can help me.

    Greetz,
    Fabian

    Steve Sierra replied 9 years, 2 months ago 6 Members · 9 Replies
  • 9 Replies
  • Dan Ebberts

    May 23, 2013 at 5:37 pm

    This should work:


    try{
    L = thisComp.layer("CONTROL PANEL").effect("PROGRAM")("Layer");
    if (L.index == index) 100 else 0;
    }catch(err){
    0
    }

    Dan

  • Fabian Bosman

    May 23, 2013 at 10:13 pm

    Thanks it worked perfectly. Could you maybe give me the expression for the checkbox control, I’m trying to understand how you did that and if it is more useful to work with a Checkbox control in my project.

    Thanks again.

    Greetz,
    Fabian

  • Dan Ebberts

    May 23, 2013 at 10:38 pm

    Like this maybe:

    cb = thisComp.layer(“CONTROL PANEL”).effect(“Checkbox Control”)(“Checkbox”);
    if (cb.value) 100 else 0;

    Dan

  • Fabian Bosman

    May 23, 2013 at 10:59 pm

    Last question I think 🙂 Is it possible if you have multiple checkboxes in one null (control) object, to select one checkbox and all the others will be unchecked? In this case for example the opacity of layer.1 will be at 100% and the other layers are at 0%. When I select another checkbox that the layer.1 checkbox will unchecked automaticly?

    Thanks again

  • Dan Ebberts

    May 23, 2013 at 11:28 pm

    You can’t really check or uncheck a checkbox with an expression. You could calculate the output value based on the state of the other check boxes, but I don’t think it’s going to reliably operate like a radio button control, if that’s what you’re after. Let’s say you defined a hierarchy where the lowest numbered checked checkbox wins. Let’s say you have number two checked, so all the others adopt the off state. Then you check number 1, so now it shows checked and the others show off. Now you check number 3. Number two wins because it is still checked and it’s now the lowest number. Messy.

    Dan

  • Eslam Amin

    October 2, 2013 at 9:58 am

    i was searching about some thing like that
    so i manage it with my expression below

    just put every expression in the check box 1 2 3

    s , s1 , s3
    link them to your controller

    // this is for the first one
    var s = effect("Checkbox Control")("Checkbox") ;
    var s1 = effect("Checkbox Control 2")("Checkbox") ;
    var s2 = effect("Checkbox Control 3")("Checkbox") ;

    if ( s1 == 1 || s2 == 1 ){
    s = 0 ;
    }else
    {
    s = effect("Checkbox Control")("Checkbox") ;
    }

    // the second
    var s = effect("Checkbox Control")("Checkbox") ;
    var s1 = effect("Checkbox Control 2")("Checkbox") ;
    var s2 = effect("Checkbox Control 3")("Checkbox") ;

    if ( s == 1 || s2 == 1 ){
    s1 = 0 ;
    }else
    {
    s1 =effect("Checkbox Control 2")("Checkbox") ;
    }
    s1

    // the third
    var s = effect("Checkbox Control")("Checkbox") ;
    var s1 = effect("Checkbox Control 2")("Checkbox") ;
    var s2 = effect("Checkbox Control 3")("Checkbox") ;

    if ( s == 1 || s1 == 1 ){
    s2 = 0 ;
    }else
    {
    s2 = effect("Checkbox Control 3")("Checkbox") ;
    }
    s2

  • Georgica-din Petrosani

    April 16, 2015 at 3:12 pm

    can you please let me know how to setup the layers in order to make it work ?
    maybe the others scripts exaplanation will be great if you can help

    a begginer beg you, sir

    thank you a lot

  • Nathan Dodge

    October 20, 2015 at 5:14 am

    I tried this out and it works initially. Only issue is it resets to the first checkbox if the cursor moves on the timeline so ultimately it doesn’t work for anything with motion.

    Anyone have success with this script?

  • Steve Sierra

    May 11, 2017 at 10:25 am

    Hi everyone,

    I am reviving this thread because I am having the same problem with my script…

    I think what is going on is that every time a value linked to one of the checkboxes is changed, all the checkboxes momentarely use their pre expression value (which is the last state it was in) and therefore ultimately go back to a “default state”.
    (I think this is going on because when I change the value of a slider linked to one of the checkboxes with the mouse and don’t let go of the left click, I can see the other checkboxes last states. When I let go of the left mouse button, the checkboxes have changed.)

    Is it possible to prevent this ?

    Thanks 😉

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