Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Reduce source text and add dots to text

  • Reduce source text and add dots to text

    Posted by Vedran Komlen on July 1, 2021 at 5:38 pm

    I’m looking for a way to actively reduce source text based on input parameter (i.e. shape layer width) and possibly add “…” after reduction.

    Lets say starting text is “Test Source” and total width of text layer is 300 px. (sourceRectAtTime()).

    Linking it to shape layer that has width of 300 px. When shape layer width is reduced to i.e. 200 px I’d like to output “Test S…” as Text.

     

    I’ve tried with linear, something like this:

     

    rectSize = thisComp.layer(“Shape Layer 1”).content(“Rectangle 1”).content(“Rectangle Path 1”).size[0];

    txtLength = text.sourceText.length;

    var x = linear(txtLength, 0, txtLength, 0, rectSize);

    text.sourceText.slice(0, x/txtLength);

     

    but that doesn’t do the trick, and also doesn’t add three dots at the end.

     

    Also I had an idea to use WHILE loop like this

     

    sizeX=thisComp.layer(“Shape Layer 1”).content(“Rectangle 1”).content(“Rectangle Path 1”).size[0];

    widthX=thisLayer.sourceRectAtTime().width;

    length=thisLayer.text.sourceText.length;

    while(widthX >= sizeX) slice(0,length-1);

     

    Different combinations of while loop ended in error output (infinite loop)

     

    I thought it’s possible to manipulate “boxTextSize” and scale it according to Shape layer size, but I guess that is possible only in scripts (extendScript).

     

    Any direction/advice is much appreciated!

    Vedran Komlen replied 5 years, 2 months ago 2 Members · 3 Replies
  • 3 Replies
  • Andrei Popa

    July 2, 2021 at 9:20 am

    It’s a little complicated so I will attach a working project for you to see what I did.

    So I made an invisible text on which I added an expression that starts at -1 frames and adds a letter each frame, going backwards.

    The first layer(the one you see) takes the sourceText from the invisible layer.

    To see the length that it should show, it goes and measures the invisible text each frame below zero. When it finds a larger value, it stops and shows the result. If the result is shorter than the initial text, it adds the 3 dots. You can control the width by the “Width Control” slider on the first layer.

    To modify the text, you need to modify the second layer. The first takes its value from this one.

  • Andrei Popa

    July 2, 2021 at 9:25 am

    I am not sure how to share files here. I can give you a dropbox download link

    https://www.dropbox.com/s/rulpt42t65hfwy2/Reduce%20text.aep?dl=0

  • Vedran Komlen

    July 2, 2021 at 3:04 pm

    Wow, very interesting approach, kind of what I was thinking of doing, knowing the width of every combination and then displaying it, but would have never done it so simple.

    I’ve realized that after removing first letter and adding “…” at the end ends up being bigger than original text so I’ve added “+1” in expression of hidden layer, so it skips the output that has only on letter removed and dots added.

    if(time<0)text.sourceText.substring(0, – timeToFrames(time)+1);

    else value

    Later I’ve realized that it skips 1st letter of every word in sentence.

    Thanks a lot Andrei,

    you’ve already helped me a ton!

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