Page 1 of 1

[Solved] Move text with expression relative to parent

Posted: August 31st, 2010, 10:11 am
by sbaden
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.

Re: Move text with expression relative to parent

Posted: August 31st, 2010, 4:34 pm
by Dan Ebberts
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

Re: Move text with expression relative to parent

Posted: August 31st, 2010, 5:58 pm
by sbaden
Thanks Dan!

I'll give this a try. Do you know if they changed this in CS5?

Re: Move text with expression relative to parent

Posted: September 1st, 2010, 9:30 am
by sbaden
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

Re: Move text with expression relative to parent

Posted: September 1st, 2010, 11:03 am
by Dan Ebberts
It works fine for me. Are both your text layers left-justified?

Dan

Re: Move text with expression relative to parent

Posted: September 1st, 2010, 12:59 pm
by sbaden
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.

Re: Move text with expression relative to parent

Posted: September 1st, 2010, 1:27 pm
by Dan Ebberts
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

Re: Move text with expression relative to parent

Posted: September 2nd, 2010, 2:05 pm
by sbaden
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?

Re: Move text with expression relative to parent

Posted: September 2nd, 2010, 2:13 pm
by Dan Ebberts
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

Re: Move text with expression relative to parent

Posted: September 2nd, 2010, 2:19 pm
by sbaden
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!

Re: Move text with expression relative to parent

Posted: September 2nd, 2010, 2:53 pm
by Dan Ebberts
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

Re: Move text with expression relative to parent

Posted: September 2nd, 2010, 4:57 pm
by sbaden
Dan you're brilliant! Works without a hitch! Thanks so much!