ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Select specific values and get the maximum value from the selection.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kyung Ko
Select specific values and get the maximum value from the selection.
on Nov 12, 2019 at 2:43:23 pm

Hi all,
Here’s what I’m trying to do.
I have 6 text layers and trying to get a longest width value from the only ones that are 100 opacity.
Here’s the code I got so far and trying to get // parts.
Please let me know if anyone has any advise. Thanks!

t1_opc = thisComp.layer(“text1”).transform.opacity;
t1_w = thisComp.layer(“text1”).sourceRectAtTime().width;

t2_opc = thisComp.layer(“text2”).transform.opacity;
t2_w = thisComp.layer(“text2”).sourceRectAtTime().width;

t3_opc = thisComp.layer(“text3”).transform.opacity;
t3_w = thisComp.layer(“text3”).sourceRectAtTime().width;

t4_opc = thisComp.layer(“text4”).transform.opacity;
t4_w = thisComp.layer(“text4”).sourceRectAtTime().width;

t5_opc = thisComp.layer(“text5”).transform.opacity;
t5_w = thisComp.layer(“text5”).sourceRectAtTime().width;

t6_opc = thisComp.layer(“text6”).transform.opacity;
t6_w = thisComp.layer(“text6”).sourceRectAtTime().width;

// Select the text layers with 100 opacity from t1 - t6;
// Add the selected text layers into the bracket bellow to get the maximum width from the selection.
// max_w = Math.max(selection)

max_w


Return to posts index

Dan Ebberts
Re: Select specific values and get the maximum value from the selection.
on Nov 12, 2019 at 6:54:42 pm

I think I'd just keep track of the max as the expression chugs through the layers:

myMax = 0;
L = thisComp.layer("text1");
if (L.opacity == 100) myMax = L.sourceRectAtTime().width;
L = thisComp.layer("text2");
if (L.opacity == 100) myMax = Math.max(myMax,L.sourceRectAtTime().width);
L = thisComp.layer("text3");
if (L.opacity == 100) myMax = Math.max(myMax,L.sourceRectAtTime().width);
L = thisComp.layer("text4");
if (L.opacity == 100) myMax = Math.max(myMax,L.sourceRectAtTime().width);
L = thisComp.layer("text5");
if (L.opacity == 100) myMax = Math.max(myMax,L.sourceRectAtTime().width);
L = thisComp.layer("text6");
if (L.opacity == 100) myMax = Math.max(myMax,L.sourceRectAtTime().width);
myMax


Dan



Return to posts index

Kyung Ko
Re: Select specific values and get the maximum value from the selection.
on Nov 12, 2019 at 7:29:43 pm

Thanks so much for the solution Dan!
It works like a charm! ☺


Return to posts index


Kyung Ko
Re: Select specific values and get the maximum value from the selection.
on Nov 12, 2019 at 8:11:07 pm

I made it work with your solution and it's perfect, but I have a question just for the learning purpose. ☺☺☺
Instead of linearly tracking down(which I think is the best way), I was trying to use 'for loop' to find the text layers in 100 opacity, and add those to 'Math.max("selected object".width . . . )'
I wonder if it's even possible.

I recently learned 'for loop' while researching for the problem, and just want to see how it can be done if it's possible.


Return to posts index

Dan Ebberts
Re: Select specific values and get the maximum value from the selection.
on Nov 12, 2019 at 8:21:50 pm

Something like this should work:


myMax = 0;
for (i = 1; i <= thisComp.numLayers; i++){
if (i == index) continue; // skip this layer
if (thisComp.layer(i).name.substr(0,4) == "text"){
L = thisComp.layer(i);
if (L.opacity == 100) myMax = Math.max(myMax,L.sourceRectAtTime().width);
}
}
myMax



Dan



Return to posts index

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