Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Motion Boutique – Text Bounds Expression

  • Motion Boutique – Text Bounds Expression

    Posted by Andres Torres on August 12, 2013 at 6:28 pm

    I’d like to alter the existing expression to only evaluate the time at start.

    If the text doesn’t change, you can save render time by evaluating the expression at t=0 only. It is recommended to Convert Expression to Keyframes when you’re done with the text layer.

    thanks.

    step = 1; // higher values speed things up (2 means two times faster) but reduce precision
    L = thisComp.layer("MyTextLayer"); // text layer whose size must be evaluated

    w = thisComp.width;
    h = thisComp.height;
    halfW = w / 2;
    halfH = h / 2;
    halfStep = step / 2;

    left = w;
    right = 0;
    top = h;
    bottom = 0;

    // find left
    found = false;
    for (x = 0; !found && x < w; x+=step)
    {
    if (L.sampleImage([x,halfH], [halfStep,halfH], true)[3] > 0)
    {
    found = true;
    if (x < left)
    left = x;
    }
    }
    // find right
    found = false;
    for (x = w; !found && x >= 0; x-=step)
    {
    if (L.sampleImage([x,halfH], [halfStep,halfH], true)[3] > 0)
    {
    found = true;
    if (x > right)
    right = x;
    }
    }
    // find top
    found = false;
    for (y = 0; !found && y < h; y+=step)
    {
    if (L.sampleImage([halfW,y], [halfW,halfStep], true)[3] > 0)
    {
    found = true;
    if (y < top)
    top = y;
    }
    }
    // find bottom
    found = false;
    for (y = h; !found && y >= 0; y-=step)
    {
    if (L.sampleImage([halfW,y], [halfW,halfStep], true)[3] > 0)
    {
    found = true;
    if (y > bottom)
    bottom = y;
    }
    }

    /*"Size of textn" + (right-left) + "x" + (bottom-top)*/
    left + "," + top + "," + (right-left) + "," + (bottom-top)

    Dan Ebberts replied 12 years, 11 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    August 12, 2013 at 7:26 pm

    I don’t think it will work. The expression has to evaluate to something on every frame. There’s no way for the expression, at a later frame, to retrieve the value it calculated at a previous frame–it would have to recalculate it, which doesn’t save you any processing time.

    Dan

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