Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Dynamic Type Maintaining Distances

  • Dynamic Type Maintaining Distances

    Posted by Chris Meadmore on August 19, 2020 at 10:30 am

    Hi all,

    Really appreciate help on this, just not getting it!

    I have 2 text layers: Headline and Body. The Headline text functions as intended, every new line re-centers the text layer and layer dynamically scale based on text length.

    The body copy is set to maintain the same distance from the Headline as more lines are added. This bit works, but as it scales the math breaks and it loses the correct distance over time.

    Have posted a project file here https://gofile.io/d/Z7reIE

    Code also below but probably a little confusing.:

    HEADLINE POSITION:

    box = thisLayer.sourceRectAtTime(time);
    offset = box.height/2;
    y = position[1] - offset;
    x = value[0];
    [x, y];

    HEADLINE SCALE:

    textwidth = thisLayer.sourceRectAtTime().width;
    s = Math.min(100*900/textwidth, 100);
    [s,s]

    BODY POSITION:

    box = thisComp.layer("HEADLINE_01").sourceRectAtTime(time);
    offset = box.height/2;
    y = position[1] + offset;
    x = value[0];
    [x, y];

    BODY NUL:

    thisComp.layer("HEADLINE_01").transform.scale[0]

    Chris Meadmore replied 6 years ago 2 Members · 5 Replies
  • 5 Replies
  • Andrei Popa

    August 19, 2020 at 3:25 pm

    sourceRectAtTime calculates the rectangle as if the scale was 100. It does not take into account the scale.
    You need to multiply the values that are not working good with one value from scale.
    Ex:


    BODY POSITION:

    headlineLayer = thisComp.layer("HEADLINE_01")
    box = headlineLayer .sourceRectAtTime(time);
    offset = box.height/2;
    y = position[1] + offset*headlineLayer.scale[1] ;
    x = value[0];
    [x, y];

    You may need to modify some of the other expressions too.

    Andrei
    My Envato portfolio.

  • Chris Meadmore

    August 20, 2020 at 8:52 am

    Amazing, that set me on the right path, thank you!

  • Chris Meadmore

    August 20, 2020 at 9:37 am

    Whilst I’ve got you here could I ask another question? ?

    In this project file I’ve got 4 Headline comps, each containing text layers with auto scaling applied.

    I need to set up an array so they all monitor each other’s scale and adjust to the smallest value. I’ve tried a few if/else expressions but can’t get it working.

    So in HEADLINE 4 – All text layers need to monitor each other’s scale and make sure they’re always consistent with one another.

    Can get it working with 2 layers but not 4.

    Thanks!

    https://gofile.io/d/eAFTbO

  • Andrei Popa

    August 20, 2020 at 3:01 pm

    I don’t know if this fits perfectly with your project, but something like this on every Headline scale


    w1 = thisComp.layer("HEADLINE_01").width;
    w2 = thisComp.layer("HEADLINE_02").width;
    w3 = thisComp.layer("HEADLINE_03").width;
    w4 = thisComp.layer("HEADLINE_04").width;
    maxWidth = Math.max(w1,w2,w3,w4);
    s = Math.min((100 * 900) / maxWidth, 100);
    [s, s];

    Andrei
    My Envato portfolio.

  • Chris Meadmore

    August 20, 2020 at 3:15 pm

    Again, thanks so much! Just had to combine that with my own to get the below and everything works perfectly.

    Thanks!

    w1 = thisComp.layer("HEADLINE_01").sourceRectAtTime().width;
    w2 = thisComp.layer("HEADLINE_02").sourceRectAtTime().width;
    w3 = thisComp.layer("HEADLINE_03").sourceRectAtTime().width;
    w4 = thisComp.layer("HEADLINE_04").sourceRectAtTime().width;
    maxWidth = Math.max(w1,w2,w3,w4);

    s = Math.min(100*900/maxWidth, 100);
    [s,s]

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