Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions sourceRect text layers which play off each other.

  • sourceRect text layers which play off each other.

    Posted by Chris Meadmore on July 2, 2019 at 9:41 am

    Hi,

    I’m using sourceRect.time to scale a text layer to a specific width. Works great.

    Now I have 2 layers which have the same expression applied and I’m trying to rig them off each other. So:

    Layer A scales to designated width unless Layer B is smaller in which case follow that.

    I’ve almost got it working with one layer, it scales itself depending on length but also monitors the other layer and adjusts accordingly. When I apply this same expression to the other layer it doesn’t work.

    Is there a way to do this without introducing extra layers / Nuls?

    Thanks for any help! Kinda urgent 😀

    textwidth = thisLayer.sourceRectAtTime().width;
    s = 100*1700/textwidth;
    b = thisComp.layer("Layer A").transform.scale;

    if(s < 100) [s,s] else b;

    Chris Meadmore replied 7 years, 1 month ago 3 Members · 6 Replies
  • 6 Replies
  • Chris Meadmore

    July 2, 2019 at 9:51 am

    Oops… think I solved it on my own. Just needed a smoke break!

    a = thisLayer.sourceRectAtTime().width;
    b = thisComp.layer("Layer A").sourceRectAtTime().width;
    c = 100*1700/a;
    d = 100*1700/b;

    if(a > b) [c,c] else [d,d];

  • Chris Meadmore

    July 2, 2019 at 9:56 am

    Never mind, still not solved.

    The layers are playing off each other perfectly but I need to cap them at 100% so they don’t scale beyond that.

  • Scott Mcgee

    July 2, 2019 at 10:20 am

    There’s probably a better way.

    You can clamp your scale to not go above 100 for example.

    s = clamp(c,0,100);

    [s,s]

  • Chris Meadmore

    July 2, 2019 at 11:17 am

    Thanks Scott!

    I’ve brought a coder into the mix and he produced the below expression which worked perfectly although we’re now struggling with trying to apply it to 3 layers and find the max value from them.

    Any ideas how to do this? Thanks so much for the help!

    Layer1Width = thisComp.layer("LINE_01").sourceRectAtTime().width;
    Layer2Width = thisComp.layer("LINE_02").sourceRectAtTime().width;

    Layer1Ratio = 100 * 1700 / Layer1Width;
    Layer2Ratio = 100 * 1700 / Layer2Width;

    Layer1Ratio = Layer1Ratio > 100 ? 100 : Layer1Ratio;
    Layer2Ratio = Layer2Ratio > 100 ? 100 : Layer2Ratio;

    if(Layer1Width > Layer2Width ) [Layer1Ratio, Layer1Ratio] else [Layer2Ratio, Layer2Ratio];

  • Andrei Popa

    July 2, 2019 at 11:32 am

    So you try to go for the largest layer, but not over 100?

    Layer1Width = thisComp.layer("LINE_01").sourceRectAtTime().width;
    Layer2Width = thisComp.layer("LINE_02").sourceRectAtTime().width;
    Layer3Width = thisComp.layer("LINE_03").sourceRectAtTime().width;

    LayerRatio = 100 * 1700 /Math.max( Layer1Width, Layer2Width, Layer3Width);
    (LayerRatio<100) ? [LayerRatio, LayerRatio] : [100,100];

    You can put however many layers you wish.

    Andrei
    My Envato portfolio.

  • Chris Meadmore

    July 2, 2019 at 11:53 am

    That is PERFECT!

    Thank you

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