Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions for loop (opacity)

  • for loop (opacity)

    Posted by Scott Mcgee on March 7, 2018 at 8:55 am

    Hey Guys,

    I’m not having much luck with this one. for loops have always been my weakest area from day one.

    val = 0;
    for( i=1; i <= thisComp.numLayers; i++){
    if (i == index) continue;
    L = thisComp.layer(i)
    if(L.transform.opacity == 0) continue;
    if(L.transform.opacity == 100){
    val = L.transform.position[1] + 40;
    break;
    }
    }
    [value[0],val]

    I’m trying to do an opacity expression that loops. If the item’s opacity is 0 it will look at the next one and position itself accordingly (Either this way or if it’s active, I don’t mind)

    But it kind of works, but not quite exactly the way I want it to.

    Essentially I two grids with 8 layers (9 if you include the header), not all layers need to be active (Or opacity 100). So if there is less than as soon as there is space (Inactive), everything moves itself up one.

    Example below

    Title
    Layer1
    Layer2
    Layer3
    Title
    Layer1
    Layer2
    Layer3

    Title
    Layer1
    Layer2
    Title
    Layer1
    Layer2
    Layer3

    Scott Mcgee replied 8 years, 5 months ago 1 Member · 2 Replies
  • 2 Replies
  • Scott Mcgee

    March 7, 2018 at 9:50 am

    Well I got it working at least.

    val = null;
    for ( i = index+1; i <= thisComp.numLayers; i++){
    try{
    L = thisComp.layer(i)
    if(L.transform.opacity == 0) continue;
    if(L.transform.opacity == 100){
    val = L.transform.position[1] + 40;
    }
    break;
    }catch(err){
    }
    }
    [value[0],val]

    Now is there a way if you go over a certain amount of layers it’ll start from the beginning.

    Title Layer2
    Layer1 Layer3
    Layer2 Layer4
    Layer3
    Layer4 Title
    Layer1
    Title Layer2
    Layer1 Layer3

  • Scott Mcgee

    March 7, 2018 at 9:59 am

    For the fact I’m struggling my guessing game is getting better.

    val = null;
    for ( i = index+1; i <= thisComp.numLayers; i++){
    try{
    L = thisComp.layer(i)
    if(L.transform.opacity == 0) continue;
    if(L.transform.opacity == 100){
    val = L.transform.position[1] + 40;
    }
    if(L.transform.position[1] > 600){
    val = thisComp.layer(“She 10”).transform.position[1];
    }
    break;
    }catch(err){
    }
    }
    [value[0],val]

    If anyone can think of a tidier way, but at least it works now.

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