Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Script for comparing layer height for positioning.

  • Script for comparing layer height for positioning.

    Posted by Billy Sides on August 6, 2013 at 8:11 pm

    I am working on a template that needs to compare the first three layers. I’m checking to see which layer is the tallest. Here is what I have for the expression.

    VH1 = thisComp.layer(1).height;
    VH2 = thisComp.layer(2).height;
    VH3 = thisComp.layer(3).height;

    VH1S = VH1*([thisComp.layer(1).transform.scale[0]]/100);
    VH2S = VH2*([thisComp.layer(2).transform.scale[0]]/100);
    VH3S = VH3*([thisComp.layer(3).transform.scale[0]]/100);

    if ( VH1S >= VH2S && VH3S )
    H = VH1S

    else if ( VH2S >= VH1S && VH3S )
    H = VH2S

    else if ( VH3S >= VH1S && VH2S )
    H = VH3S

    50 + H - VH3S

    The problem is that in this case the third if statement for some reason is never true.

    I tried changing the code like so:
    VH1 = thisComp.layer(1).height;
    VH2 = thisComp.layer(2).height;
    VH3 = thisComp.layer(3).height;

    VH1S = VH1*([thisComp.layer(1).transform.scale[0]]/100);
    VH2S = VH2*([thisComp.layer(2).transform.scale[0]]/100);
    VH3S = VH3*([thisComp.layer(3).transform.scale[0]]/100);

    if ( VH1S >= VH2S && VH3S )
    H = VH1S

    if ( VH2S >= VH1S && VH3S )
    H = VH2S

    if ( VH3S >= VH1S && VH2S )
    H = VH3S

    50 + H - VH3S

    But then the second if statement is never true…am I missing something?

    Any help is appreciated.

    -bsides

    Billy Sides replied 12 years, 9 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    August 6, 2013 at 8:59 pm

    Your condition tests need to be more like this:

    if((VH1S >= VH2S) && (VH1S >= VH3S))

    and your last conditional should just be an else (instead of an else if)

    Dan

  • Billy Sides

    August 6, 2013 at 9:32 pm

    Perfect! I think I knew that at some point…but I forget little things like that when I haven’t used it in awhile.

    Thanks again Dan you’re the best!

    -bsides

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