ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Find the XY co-ordinates of a text layer

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
siva kumar
Find the XY co-ordinates of a text layer
on Jul 16, 2015 at 6:48:56 am
Last Edited By siva kumar on Jul 16, 2015 at 7:00:25 am

Hi,

I need to add image in between the text , so i need to calculate the starting point of the text layer.

For eg: i need to add " " here in this line.

in this sentence i need to replace the " " with vector image. To place the vector image i need to calculate the position programatically. If i am able to know the starting x co-ordinate i can add the width of "i need to add" to the starting x-coordinate. Any other way to find the solutions are also welcome. Thanks in advance.


Return to posts index

Dave LaRonde
Re: Find the XY co-ordinates of a text layer
on Jul 16, 2015 at 2:03:39 pm

There is no need to know the coordinates. You can parent the new layer to the text layer. Once parented, it will maintain its position on the text layer, including rotation and scale.

Dave LaRonde
Promotion Producer
KGAN (CBS) & KFXA (Fox) Cedar Rapids, IA


Return to posts index

Kevin Camp
Re: Find the XY co-ordinates of a text layer
on Jul 16, 2015 at 5:20:48 pm

in cc 2014 and later, there is an expression function that can get the size a text layer (or a shape layer). it's sourceRectAtTime().

so, for the position of the vector graphic you could use that function to get the width of the preceding text layer, add it to the position of that text layer.

there's a few things that i'll assume, first, the preceding text layer is left justified (so anchor point is on the left edge). second, the vector graphic's anchor point is in it's center.

in the position property of the vector graphic, try this expression:

myText = thisComp.layer('Your Text Layer'); //point this at your text layer
pad = 10;
textRec = myText.sourceRectAtTime(time);
x = myText.position[0] + textRec.width + pad + (width * scale[0] / 200);
[x, value[1]]


that should place the vector layer at the end of the text layer. set the pad value as needed to create extra space between the text layer and the vector layer.

to add the second text layer at the end of the vector image you modify that expression to something like this:

vectGfx = thisComp.layer("YourVectorGfx");
pad = 10;
x = vectGfx.position[0] + (vectGfx.width * vectGfx.scale[0] / 200) + pad;
[x, value[1]]


Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index


siva kumar
Re: Find the XY co-ordinates of a text layer
on Jul 17, 2015 at 5:00:18 am

Hi,
Thanks for your response. My text is center aligned and here the width and scale refers to text layer or vector image ?


Return to posts index

Kevin Camp
Re: Find the XY co-ordinates of a text layer
on Jul 17, 2015 at 4:23:12 pm

[siva kumar] "here the width and scale refers to text layer or vector image ?"

the set up would involve sandwiching a layer (vector image) between 2 text layers.

the vector image would look at the preceding text layer's position and width (along with it's own width) to determine it's horizontal position.

the second text layer would look at the vector layer's width and position to determine it's horizontal position.

i would keep the text layer's justification as left (it makes the expressions easier). if you needed to center all three layers horizontally, then you could add an expression to the first text layer's position:

vectGfx = thisComp.layer("MyVectorGfx");
text2Lyr = thisComp.layer("My Second Text Layer");
pad = 10; // set this as the same pad value as the other expressions
xOffset = 0; // use this to offset x position if it doesn't need to center in comp

txt1Rect = sourceRectAtTime(time);
txt2Rect = text2Lyr.sourceRectAtTime(time);

wTotal = txt1Rect.width + (vectGfx.width * vectGfx.scale[0] / 100) + txt2Rect.width + (pad * 2 )- position[0];
x = (thisComp.width - wTotal) / 2 + xOffset;

[x, value[1]]


Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

Kevin Camp
Re: Find the XY co-ordinates of a text layer
on Jul 17, 2015 at 5:24:29 pm
Last Edited By Kevin Camp on Jul 17, 2015 at 5:25:26 pm

you could also do something similar with parent and without the first 2 expression and just a single expression on the first text line...

you'd make the first text line right justified and the second text layer left justified, then parent the vector layer and the other text layer to the first text layer.

arrange them so they are in a line, and then on the first text layer you'd add this expression:

vectGfx = thisComp.layer("My Vector Gfx");
text2Lyr = thisComp.layer("My Second Text Layer");
xOffset = 0;

txt1Rect = sourceRectAtTime(time);
txt2Rect = text2Lyr.sourceRectAtTime(time);

wTotal = (vectGfx.width * vectGfx.scale[0] / 100) + txt2Rect.width - txt1Rect.width;
x = (thisComp.width - wTotal) / 2 + xOffset;

[x, value[1]]


it should do a reasonable job of keeping all the layers centered on screen when the text or the vector layer change. it may not be perfect, do to the sourceRectAtTime() function trimming off spaces, but it should do a pretty good job

Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

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