[Solved] Move text with expression relative to parent

Moderators: Disciple, zlovatt

Post Reply
sbaden
Posts: 35
Joined: June 16th, 2009, 1:07 pm
Location: Santa Clarita, CA

I have two text fields (first and last name) and I'm trying to move the last name relative to the position of the first name. The animation starts out with the entire first name (john) and entire last name (smith). I'm using an animator on the first name (Range Selector) to reduce full first name to first initial. As the first name animates down to first initial the last name should move to the left to keep the same spacing.

Here is the expression I'm using on the position of the last name:

Code: Select all

x = parent.width + 10;
y = 0;
[x,y]
Using this code pushes the last name all the way off the window to the right. I'm not sure how it's interpreting the parent width or how to fix this. I'm using AE CS3 but might be able to use CS4 if necessary.
Last edited by sbaden on September 8th, 2010, 1:13 pm, edited 1 time in total.
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

Unfortunately, you can't directly get the bounds of a text layer with an expression. You can use sampleImage() to find the edges though. Assusming your text layers are left-justified, something like this should be close:

Code: Select all

L = parent;
for ( i = L.width; i >= 0; i--){
  s = L.sampleImage([i,L.width/2],[.5,L.width/2],true,time);
  if (s[3] > 0) break;
}

[i + 10 - L.transform.position[0],value[1]]
Dan
sbaden
Posts: 35
Joined: June 16th, 2009, 1:07 pm
Location: Santa Clarita, CA

Thanks Dan!

I'll give this a try. Do you know if they changed this in CS5?
sbaden
Posts: 35
Joined: June 16th, 2009, 1:07 pm
Location: Santa Clarita, CA

Okay Dan,

I tried the expression and it works better but it is still doing something strange. The first and last name start screen right and move to left to settle. On the far right they are separated by roughly 100+ pixels. As the names move left they get closer and then overlap. The last name settles at 10-20 pixels right from the flush left position of the first name. The smaller the first name the more to the left the last name moves. If the first name is 4-5 characters the last name moves left of the flush left position of the first name.

Hope this makes sense... :?

Thanks,
Shawn
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

It works fine for me. Are both your text layers left-justified?

Dan
sbaden
Posts: 35
Joined: June 16th, 2009, 1:07 pm
Location: Santa Clarita, CA

I checked and they are both justified left. I tested the expression again by creating a new project with just the first and last name. It worked perfectly but I found the problem. It works when I have the last name parented to the first name but when I add another text layer and parent it to the last name (basically to do the same thing with the text line and the last name that the last name is doing to the first name) it doesn't work with the additional text layer.

So basically it works if I only have last name parented to the first name. When the first layer is parented to another layer it starts acting strange.
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

Ah, OK. This should fix it:

Code: Select all

L = parent;
for ( i = L.width; i >= 0; i--){
  s = L.sampleImage([i,L.width/2],[.5,L.width/2],true,time);
  if (s[3] > 0) break;
}

[i + 10 - L.toWorld(L.anchorPoint)[0],value[1]]

Dan
sbaden
Posts: 35
Joined: June 16th, 2009, 1:07 pm
Location: Santa Clarita, CA

This works perfectly! I'm getting some hitch in the animation though. At some point in the animation (no association with a key frame) the last name moves towards the first name and then away within two frames and the note line does the same towards the last name and then away.

Any ideas?
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

Hard to say without seeing it. The expression is looking for the right-most pixel that has a non-zero alpha, so anything that could affect that (motion blur?) would be suspect.

Dan
sbaden
Posts: 35
Joined: June 16th, 2009, 1:07 pm
Location: Santa Clarita, CA

I just went through all the layers and turned off a glow effect on all the layers and that seems to have fixed the problem... Crazy...

Thank you very much for all your help Dan!
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

Try changing the sampling line to this:

s = L.sampleImage([i,L.width/2],[.5,L.width/2],false,time);

That should make it sample before any effects are applied to the layer.

Dan
sbaden
Posts: 35
Joined: June 16th, 2009, 1:07 pm
Location: Santa Clarita, CA

Dan you're brilliant! Works without a hitch! Thanks so much!
Post Reply