FORUMS: list search recent posts

Parenting text layers to other text layers

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Bart Remmers
Parenting text layers to other text layers
on May 25, 2016 at 10:16:52 am

Hi there,

I've been messing around with this but I can't seem to get this right. Let me first share a screenshot of what I want to achieve:



You can see 4 texts. Let's discuss the upper two (Aligned to the right). I want these two texts to be parented to each other. All that I want is the left text layer ("Parent me to"), which is parented to the right one ("This text"to move to the right when the second part of the sentance gets longer (so when it has more width/characters).

This way I hope to create flexible texts like shown in the second example. As you can see, I want the other text layers to adjust their position depending on the width of the variable text layer (the names "Pete/Joanna").

I was thinking working with Nulls that move along with the edges of the text layer, but they don't really seem to do that (so I could parent the second text layer that needs to move when the variable textlayer has been changed).

I tried to google this and took a good look around on Creative Cow, but I couldn't find anything on this specific thing. I hope someone can help me further along with this and I hope that my question is clear enough, if not I can always try to explain again ;)

Thank you guys in advance!

Bart.


Return to posts index

Dan Ebberts
Re: Parenting text layers to other text layers
on May 25, 2016 at 8:13:54 pm
Last Edited By Dan Ebberts on May 25, 2016 at 8:19:18 pm

Here are a couple of examples that should help. This one will right justify to another text layer on the right:

gap = 20;
L = thisComp.layer("other layer");
r = L.sourceRectAtTime(time,false);
hisLeft = L.position[0] + (r.left - L.anchorPoint[0])*L.scale[0]/100;
r = sourceRectAtTime(time,false);
myRight = position[0] + (r.left + r.width - anchorPoint[0])*scale[0]/100;
delta = hisLeft - myRight;
value + delta - gap


This one will left justify to another text layer on the left:

gap = 20;
L = thisComp.layer("other layer");
r = L.sourceRectAtTime(time,false);
hisRight = L.position[0] + (r.left + r.width - L.anchorPoint[0])*L.scale[0]/100;
r = sourceRectAtTime(time,false);
myLeft = position[0] + (r.left - anchorPoint[0])*scale[0]/100;
delta = hisRight - myLeft;
value + delta + gap

In both, you need to set the gap variable to something that makes sense for your font size.


Dan


EDIT: Oops, I posted the same expression twice. This should be better.



Return to posts index

Bart Remmers
Re: Parenting text layers to other text layers
on May 27, 2016 at 2:39:59 pm

Hi Dan,

Thank you for your expression again! It works like a charm in both examples!! Exactly what I needed!
I'm very happy that you helped me out with this! A million thanks! This opens up some possibilities that I've never dreamed off!

Bart.


Return to posts index


Kalle Kannisto
Re: Parenting text layers to other text layers
on May 26, 2016 at 5:45:42 pm

Another option is to use a placeholder character such as an asterisk and replace it.

For instance, set the text to "Hello *! How are you?" and use this expression to get the name from a text layer "name":

text_array = text.sourceText.split("*");
text_array[0]+thisComp.layer("name").text.sourceText+text_array[1]


Although if you actually want different colors for the different pieces of text, that's not going to work.


Return to posts index

Bart Remmers
Re: Parenting text layers to other text layers
on May 27, 2016 at 2:43:20 pm

Hi Kalle,

Thank you for your expression. Not in all instances is it required for my texts to have different colors, but I'd like to have the possibility to change it in whatever I'd like it to be. It's good that you pointed this out. I've tried your and Dan's expression and I went with Dan's because this one fits more to my needs. But I'd still want to thank you offcourse for your effort and helping me out. So thank you for your input. Much appreciated!!

I'm sure I'll be back sometime soon when I can't achieve what I'm trying.

Bart.


Return to posts index

Bart Remmers
Re: Parenting text layers to other text layers
on Jun 2, 2016 at 8:23:41 am

Quick question; would there be a simple way to have the three layers (the second example that I've shown in the first post in this topic) centered in the middle of my composition? Right now if the left one contains 3 characters and right one would contain 10 characters and I centered the middle one, it wouldn't be centered anymore.

Bart.


Return to posts index


Bart Remmers
Re: Parenting text layers to other text layers
on Jun 2, 2016 at 12:36:29 pm

Hi Kalle,

I've been messing around with your script. It's really usefull too! Thanks again for it.
Is it possible to split two times in one text layer?

Like this:

I put this in my text layer: "*, #"

text_array = text.sourceText.split("*");
text_array[0]+thisComp.layer("text_1").text.sourceText+text_array[1]

text_array = text.sourceText.split("#");
text_array[0]+thisComp.layer("text_2").text.sourceText+text_array[1]


When I try this it only works on the last one, so this will show up like this:

"*, text_2"

Do you have any idea if it's possible to split it twice in one layer?

Bart.


Return to posts index

Kalle Kannisto
Re: Parenting text layers to other text layers
on Jun 2, 2016 at 12:53:41 pm

You'd have to keep using the result and split it further, like so:

text_array = text.sourceText.split("*");
text_array2=text_array[0]+thisComp.layer("name").text.sourceText+text_array[1];
text_array3 = text_array2.split("#");
text_array3[0]+thisComp.layer("day").text.sourceText+text_array3[1]


So, for example, the original layer would have the text "Hello *, have a good #!" and the comp would have two text source layers, one with the layer name "name" and another with "day". They would both be replaced.

Centering the text using this method is easy as you can use the centered paragraph, but it would be the same style throughout the text, so will work only for those instances.


Return to posts index

Bart Remmers
Re: Parenting text layers to other text layers
on Jun 2, 2016 at 1:44:20 pm

Kalle, you are a true hero! Thank you!


Return to posts index

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