Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Autoscale Text Box for two lines of text

  • Adam Greenberg

    November 3, 2023 at 1:22 pm

    here is the code for people who may stumble on this thread one day, to be applied to the path ( you need to add the path property to the rectangle of the shape layer )

    margin = 30;

    t1=thisComp.layer(“textLayer”);

    s1=t1.sourceRectAtTime();

    t2=thisComp.layer(“textLayer 2”);

    s2=t2.sourceRectAtTime();

    l = t1.toComp([s1.left, s1.top])[0] – margin;

    r = t2.toComp([s2.left+s2.width, s1.top])[0] + margin;

    t = Math.min(t1.toComp([s1.left, s1.top])[1], t2.toComp([s2.left+s2.width, s2.top])[1]) – margin;

    b = Math.max(t1.toComp([s1.left, s1.top+s1.height])[1], t2.toComp([s2.left+s2.width, s2.top+s2.height])[1]) + margin;

    y = thisComp.layer(“textLayer”).toComp([thisComp.layer(“textLayer”).sourceRectAtTime().left+thisComp.layer(“textLayer”).sourceRectAtTime().width,0],2)[0]+margin;

    z = thisComp.layer(“textLayer 2”).toComp([thisComp.layer(“textLayer 2”).sourceRectAtTime().left+thisComp.layer(“textLayer 2”).sourceRectAtTime().width,0],2)[0]+margin;

    x = Math.max(y,z);

    createPath( [fromComp([l,t]), fromComp([x,t]), fromComp([x,b]), fromComp([l,b])], [],[], true);

  • Kyle Jenkins

    June 26, 2025 at 7:47 pm

    I did indeed stumble upon this thread! I’m looking to build a text with a background shape that scales appropriately, much like this one, but what I’m trying to do is have the background shape path scale down, and center on the remaining text when a layer is set to 0 opacity (checkbox/(0,1)) Layer on, larger text box. Layer off, smaller textbox. Does this make sense? (my eyes are crossing as I try to wrap my heaad around this one)

  • Dan Ebberts

    June 26, 2025 at 11:09 pm

    Assuming your text layers (“Text 1” and “Text 2”) have checkboxes to indicate their inclusion in the shape calculation, something like this should work:

    m = 15; // margin
    L1 = thisComp.layer("Text 1");
    L2 = thisComp.layer("Text 2");
    cb1 = L1.effect("Checkbox Control")("Checkbox").value;
    cb2 = L2.effect("Checkbox Control")("Checkbox").value;
    r1 = L1.sourceRectAtTime(time,false);
    r2 = L2.sourceRectAtTime(time,false);
    ul1 = L1.toComp([r1.left,r1.top]);
    lr1 = L1.toComp([r1.left+r1.width,r1.top+r1.height]);
    ul2 = L2.toComp([r2.left,r2.top]);
    lr2 = L2.toComp([r2.left+r2.width,r2.top+r2.height]);
    if (cb1 && cb2){
    l = Math.min(ul1[0],ul2[0]); // left
    r = Math.max(lr1[0],lr2[0]); // right
    t = Math.min(ul1[1],ul2[1]); // top
    b = Math.max(lr1[1],lr2[1]); // bottom
    }else if (cb1){
    l = ul1[0];
    r = lr1[0];
    t = ul1[1];
    b = lr1[1];
    }else if (cb2){
    l = ul2[0];
    r = lr2[0];
    t = ul2[1];
    b = lr2[1];
    }else{
    l = r = t = b = -100;
    }
    p = [fromComp([l-m,t-m]),fromComp([r+m,t-m]),fromComp([r+m,b+m]),fromComp([l-m,b+m])];
    createPath(p,[],[],true)
Page 2 of 2

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