ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Layer Position Relative to Text Length

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jason Smart
Layer Position Relative to Text Length
on Aug 14, 2015 at 5:48:07 pm

Hello, 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!


Return to posts index

Dan Ebberts
Re: Layer Position Relative to Text Length
on Aug 14, 2015 at 6:38:12 pm

This 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



Return to posts index

Jason Smart
Re: Layer Position Relative to Text Length
on Aug 14, 2015 at 7:03:40 pm

WOW.

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!


Return to posts index


Jason Smart
Re: Layer Position Relative to Text Length
on Aug 31, 2015 at 11:10:23 pm

Hey 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!


Return to posts index

Dan Ebberts
Re: Layer Position Relative to Text Length
on Aug 31, 2015 at 11:39:01 pm

Yes, 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



Return to posts index

Jason Smart
Re: Layer Position Relative to Text Length
on Sep 1, 2015 at 4:01:28 pm

Ah I see, so I'm assuming it's not as simple as replacing sourceRectAtTime() with sampleImage()?


Return to posts index


Dan Ebberts
Re: Layer Position Relative to Text Length
on Sep 1, 2015 at 4:10:09 pm

No, 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



Return to posts index

Jason Smart
Re: Layer Position Relative to Text Length
on Sep 1, 2015 at 4:18:54 pm

Great, thank you for all your help. It's much appreciated!


Return to posts index

Sven Heib
Re: Layer Position Relative to Text Length
on Sep 2, 2015 at 4:51:30 pm

How 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


Return to posts index


Dan Ebberts
Re: Layer Position Relative to Text Length
on Sep 2, 2015 at 5:37:37 pm

Like 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



Return to posts index

Andrew Musselman
Re: Layer Position Relative to Text Length
on Jun 7, 2018 at 9:16:34 pm

I 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.


Return to posts index

Dan Ebberts
Re: Layer Position Relative to Text Length
on Jun 7, 2018 at 10:52:17 pm

That would be a Position expression for a layer that you want to line up to the right of the text layer.


Dan



Return to posts index


Andrew Musselman
Re: Layer Position Relative to Text Length
on Jun 8, 2018 at 2:49:54 am

Awesome!!! And what if I wanted to use it for text on the left side of the layer?

Never Stop Learning.


Return to posts index

Kalleheikki Kannisto
Re: Layer Position Relative to Text Length
on Jun 10, 2018 at 6:33:11 am

Although I didn't read that very carefully, I expect it should work by changing the last line to

[x-gap-width/2,value[1]]

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]