Activity › Forums › Adobe After Effects Expressions › Layer Position Relative to Text Length
-
Layer Position Relative to Text Length
Posted by Jason Smart on August 14, 2015 at 5:48 pmHello, I am trying to find an expression that will move the position of a layer relative to the size or length of the text layer next to it.
For example, I have a layer on the left and a layer on the right. I want to add a longer series of text to my left layer and I want the layer on the right to move it’s position and stay the same distance away from the text layer on my left.
I hope that makes sense. Any help is appreciated!
Tanja Burgin replied 2 years, 8 months ago 7 Members · 17 Replies -
17 Replies
-
Dan Ebberts
August 14, 2015 at 6:38 pmThis should give you the x coordinate of the right edge of the text layer:
L = thisComp.layer(“text”);
rect = L.sourceRectAtTime(time,false);
x = L.toComp([rect.left+rect.width,0])[0];So something like this would position a layer 10 pixels to the right of the text:
gap = 10;
L = thisComp.layer(“text”);
rect = L.sourceRectAtTime(time,false);
x = L.toComp([rect.left+rect.width,0])[0];
[x+gap+width/2,value[1]]Dan
-
Jason Smart
August 14, 2015 at 7:03 pmWOW.
You, sir, are amazing. Thank you so very much, that worked perfectly and will definitely save us a lot of time. Very very grateful, Dan!
-
Jason Smart
August 31, 2015 at 11:10 pmHey Dan,
That expression was working brilliantly in CC 2014 but when I tried to use it in CC and CS6 it gave me an undefined error message. Was there anything in there that was specific to newer versions of AE?
Thanks so much! -
Dan Ebberts
August 31, 2015 at 11:39 pmYes, I think sourceRectAtTime() was added with version 13.2 (update to CC 2014). Previous versions have to a sampleImage() hack, which is just plain ugly.
Dan
-
Jason Smart
September 1, 2015 at 4:01 pmAh I see, so I’m assuming it’s not as simple as replacing sourceRectAtTime() with sampleImage()?
-
Dan Ebberts
September 1, 2015 at 4:10 pmNo, you’d have to create a loop that starts at the right edge of the comp and moves left until it encounters non-zero alpha. You should be able to find examples here by searching for sampleImage.
Dan
-
Sven Heib
September 2, 2015 at 4:51 pmHow can I use the script, if I want my layer to stay relatively on the left side of the text.
I tried different things but the layer doesn’t stay on one place. Thanks!
Greetings
Sven -
Dan Ebberts
September 2, 2015 at 5:37 pmLike this maybe:
gap = 10;
L = thisComp.layer(“text”);
rect = L.sourceRectAtTime(time,false);
x = L.toComp([rect.left,0])[0];
[x-gap-width/2,value[1]]Dan
-
Andrew Musselman
June 7, 2018 at 9:16 pmI know this is an old thread, and I’m not that great with expressions. This should do exactly what I need it to, but how do I use it? Where on which layer does this get pasted?
Thanks for the help!
L = thisComp.layer("text");
rect = L.sourceRectAtTime(time,false);
x = L.toComp([rect.left+rect.width,0])[0];So something like this would position a layer 10 pixels to the right of the text:
gap = 10;
L = thisComp.layer("text");
rect = L.sourceRectAtTime(time,false);
x = L.toComp([rect.left+rect.width,0])[0];
[x+gap+width/2,value[1]]Never Stop Learning.
Reply to this Discussion! Login or Sign Up