ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

for loop (opacity)

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Scott McGee
for loop (opacity)
on Mar 7, 2018 at 8:55:26 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


Return to posts index

Scott McGee
Re: for loop (opacity)
on Mar 7, 2018 at 9:50:14 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


Return to posts index

Scott McGee
Re: for loop (opacity)
on Mar 7, 2018 at 9:59:12 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.


Return to posts index

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