Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Changing Shape Layers size (width) due to text width

  • Changing Shape Layers size (width) due to text width

  • Filip Vandueren

    July 23, 2020 at 9:33 am

    Like this (Rectangle size):

    t = thisComp.layer("my_text");
    tRect = t.sourceRectAtTime(time,false);
    tUL = t.toComp([tRect.left,]);
    tLR = t.toComp([tRect.left+tRect.width,]);
    myRect = sourceRectAtTime(time,false);
    myUL = toComp([myRect.left,]);
    myLR = toComp([myRect.left+myRect.width,]);
    textSize =;
    margin = textSize * 0.8;
    [(tLR[0]-tUL[0] + 2*margin)/(myLR[0]-myUL[0]),(tLR[1]-tUL[1]+ 2*margin)/(myLR[1]-myUL[1])]*100;

    .style just looks at the fontSize of the very first Character, so if for some layout-reason that character was set at a smaller size and you want to look at a different character, you should use this:

    textSize = t.text.sourceText.getStyleAt(1).fontSize;

    the index is 0-based, so this example will look at the fontSize of the second character.

  • Filip Vandueren

    July 23, 2020 at 9:48 am


    instead of making the box with rectangle and two expressions, it is better to do it with a Path-shape:

    expression for Path of a shapeLayer:

    sr = t.sourceRectAtTime();

    marginH = * 0.5;
    marginV = marginH * 0.75;

    tl = fromCompToSurface(t.toComp([sr.left - marginH, - marginV]));
    tr = fromCompToSurface(t.toComp([sr.left + sr.width + marginH, - marginV]));
    br = fromCompToSurface(t.toComp([sr.left + sr.width + marginH, + sr.height + marginV]));
    bl = fromCompToSurface(t.toComp([sr.left - marginH, + sr.height + marginV]));

    createPath( [tl,tr,br,bl], [], [], true);

    Add Fill, Stroke, rounded corners to taste.

    The upside of this method is that the Path text-box can rotate with the Text. Even if the Text is rotating in 3D.

  • Ter Ber

    July 23, 2020 at 1:08 pm

    Perfect….absolutely perfect!
    Asking for help and being blessed with someone else, whom you’ve never met and from any part of the world to collaborate and showing kindness is the most satisfying thing.

    Thank you SO much Filip (and everyone else here) for your contributions.

  • Ter Ber

    August 1, 2020 at 12:18 pm
Viewing 21 - 24 of 24 posts

Log in to reply.

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