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

  • Kim Nielsen

    November 20, 2010 at 11:48 pm

    Hey Dan,

    I am not sure if I am reposting my former message, but here goes.
    Pardon me if I didn’t explain it enough in my former message. English is my second language… and code is probably my 1000th language. If not something almost as alien.

    Well yeah anyway your code did exactly the opposite of what I tried to convey.
    What happens now asfar as I understand is:

    “I” places itself at the bottom of “L”

    I wanted the bottom of “I” to place itself at the top of L

    (I am trying to make a text stay 200px away from the bottom edge of my comp. No matter long the text)

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

  • Dan Ebberts

    November 21, 2010 at 12:13 am

    I think that’s the only permutation left. 🙂


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

    Dan

  • Kim Nielsen

    November 22, 2010 at 11:37 am

    Hi again Dan,

    Let me try and explain in pictures:
    This is what happens now:
    https://dl.dropbox.com/u/11798518/LI.jpg

    Right now the top of
    iiiii places itself at the top of L
    I want this to happen:

    https://dl.dropbox.com/u/11798518/IL.jpg

    The bottom i to place itself at the top of L
    I just can’t get this to work, Ive been messing around/trying to combine and change the script for hours now.I just can get it to register the bottom of I.

  • Dan Ebberts

    November 22, 2010 at 4:25 pm

    I can see three possible options.

    1. Move the anchor point of the “iiii” layer to the bottom of the layer.

    2. Add an offset to the last line of the expression like this:

    [value[0],i – 85]

    3. A more complicated solution where the expression has to find the lower extend of its own layer in addition to the upper extent of the other layer.

    Dan

  • Kim Nielsen

    November 22, 2010 at 9:48 pm

    Heh!

    Well shit then I am officially out of luck.

    1. Moved the anchorpoint to the bottom of the text layer, but since the content of this varies it doesn’t place itself correct in relation to L.

    2. Tried this aswell, but ran into the same problem as above. It defeats the purpose, since the content of the iii layer differs and the hardcoded value doesn’t accommodate this.

    Hell… allright I guess I will just have to deal with this manually. the lower extend of the layer should always be the same of amount of space from the comp edge… But I guess thats not the obstacle, meh.

    Thanks for trying Dan, I appreciate it.

    😀

  • Dan Ebberts

    November 22, 2010 at 11:31 pm

    It sounds like option 3) then. This one first finds the bottom of the text in its own layer, then finds the top of the target layer text, then moves the layer enough to put it on top of the target layer. I think it’s what you’re after.


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

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

    value + [0, y2-y1]

    Dan

  • Kim Nielsen

    November 23, 2010 at 8:13 am

    At some point.
    Someone gotta collect all the nuggets of gold you create here on this board.
    This is amazing, and I can’t imagine that it wouldnt be very useful to everybody who works with templates and large quantities of dynamic text.

    Thank you, thank you, thank you.

  • Mike Headley

    February 23, 2012 at 5:30 pm

    Hey all,

    Long time reader, first time poster, here. I’m currently trying to apply the first expression listed (for right justified text) to the position of a solid layer. However, when I click away from the expression field after entering the script I get this error message:

    ———————————-
    After Effects warning: Expected: ;
    Expression disabled

    Error occurred at line 3.
    Comp: ‘Comp1’
    Layer: 1 (‘White Solid 1’)
    Property: ‘Position’

    ———————————-

    I’m currently using a test comp while I try to figure this out. That’s why the above comp and layer names are generic. I received the same message within my actual project as well. I’m pretty inexperienced with expressions beyond the basics, so please forgive me if this is something really simple. Any support is greatly appreciated.

    Thanks in advance,
    -Mike H.

    L = thisComp.layer(TEST);
    for (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

    February 23, 2012 at 5:41 pm

    Your layer name needs to be in quotes:

    L = thisComp.layer(“TEST”);

    Dan

  • Mike Headley

    February 23, 2012 at 11:47 pm

    Hey Dan,

    Thanks for the quick reply. I surrounded the layer name with quotes, but I’m still getting the same error message.

    -Mike H.

    L = thisComp.layer("TEST");
    for (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]]

Page 3 of 4

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