Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions attaching an object to an updatable string of text

  • Dan Ebberts

    February 23, 2012 at 11:56 pm

    Your code got mangled somewhere along the line. Try this:


    L = thisComp.layer("TEST");
    for (i = 0; i <= L.width; i++){
    temp = L.sampleImage([i,thisComp.height/2],[0.5,thisComp.height/2],true,time);
    if (temp[3] > 0) break;
    }

    [i,value[1]]

    Dan

  • Mike Headley

    February 24, 2012 at 12:22 am

    Dan,

    That did the trick! Thank you so much for the support. I do have a followup question, though. While the expression seems to be working, the solid layer is now overlapping the text layer even as I add or remove text. It actually seems that the left edge of the solid is aligned to the left edge of the textbox. I also can’t move the solid with the selection tool once the expression is activated. Is there a way for me to manually adjust the position of the solid within the expression? I was able to find a workaround by applying the expression to a null object, then parenting my solid to the null.

    Thanks again,
    -Mike H.

  • Dan Ebberts

    February 24, 2012 at 12:35 am

    I would just move the anchor point to adjust the x, adjust the y by dragging the layer.

    Dan

  • Mike Headley

    February 24, 2012 at 12:45 am

    Eureka, that works! Thanks again for the help. This expression is really going to save me a lot of time.

    Cheers,
    -Mike H.

  • Vojtěch Palme

    December 14, 2012 at 5:50 pm

    Dan. You’ve been tremendous help. I used the script for left adjusted text

    L = thisComp.layer("TITLE");
    for (i = thisComp.width; i >= 0; i--){
    temp = L.sampleImage([i,thisComp.height/2],[0.5,thisComp.height/2],true,time);
    if (temp[3] > 0) break;
    }
    [i,value[1]]

    and aplyed it to scale of layer on background of that text. It works. But when I load the “TITLE” content from external .txt

    $.evalFile("C:/.../TITLE.txt");
    try {
    eval(title1)[0]
    } catch (err) {
    "not found"
    }

    and change the text within, I get this error

    After Effects warning: Timeout while waiting for the engine
    Expression disabled.
    Error occurred at line 4.
    Comp: ‘TABULKA1’
    Layer: 16 (‘Title bg’)
    Property: ‘Scale’

    is there some way to maybe let the scale expression wait until the text is loaded? Seems to me that is looping it self or something..

    And one more question, Is there a way to get number of lines of text? Or at least heigh of the text field? So when I paste text into some layer, the animator would readjust itself acordingly to display one row per second.
    Thank you

  • Cameron Pinegar

    August 9, 2017 at 8:22 pm

    Hi Dan,

    I’m amazed by this script, I’ve been looking for something like this for a long time. I’m using the code to create dynamic underlines that change automatically with the width of the text. I’m parenting one null object to the position of the left aligned text and using your code to parent another null object to the ragged right side of the text. I’m then using the connect layers plugin to create a stroke that connects the two null objects (thus creating the underline). It seems to be the perfect way to solve my need for dynamic underlines, but the one issue I’m having is once I’ve pasted your script it becomes very taxing on my CPU and doesn’t end up helping me save the time I was hoping to save. My laptop is not very beefy, but I’m baffled because the script seems pretty simple and I feel like I’ve used much more complicated scripts without this kind of lag. Any suggestions?

    MacBook Pro (Retina, 15-inch, Late 2013)
    2.3 GHz Intel Core i7
    16 GB 1600 MHz DDR3
    NVIDIA GeForce GT 750M 2048 MB
    Intel Iris Pro 1536 MB

    L = thisComp.layer("My name is Jonas.");
    for (i = thisComp.width; i >= 0; i--){
    temp = L.sampleImage([i,thisComp.height/2],[0.5,thisComp.height/2],true,time);
    if (temp[3] > 0) break;
    }
    [i,value[1]]

  • Dan Ebberts

    August 9, 2017 at 9:31 pm

    Anything that has sampleImage() in a loop is going to be slow. If you have a recent version of AE, you should switch to a solution that uses sourceRectAtTime() to find the edges of the text.

    Dan

  • Cameron Pinegar

    August 9, 2017 at 10:05 pm

    Thanks, Dan. That pointed me in the right direction!

Page 4 of 4

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