Copy link to clipboard
Copied
Morning all,
Got another one that I need help with (and this one's actually a two-parter).
The first part is the easy part--I'm trying to get the actual size of a text layer, I found an old expression that purports to do it but it's erroring out. This is the expression:
targetLayer = thisComp.layer("Name Name Name Name");
h = targetLayer.sourceRectAtTime().height;
s = targetLayer.transform.scale[1];
p = (s – 100)* .01;
finalSize = w + p * h;
finalSize
The error is coming in at this line: "p = (s – 100)* .01;"
AE is calling it a syntax error with an invalid or unexpected token. I'm not sure why, but that's what's happening. Can anybody help me with this one?
Second half of the problem, and this is more about figuring out the math than anything else (so if there are any math whizzes out there I need your help!). What I'm using this for is to create an end credits sequence, and what I'm looking to do is center everything vertically and horizontally on the screen. The challenge is, the credits each have a title text layer, followed by an orange bar (shape layer), and then whatever names come after. The Y positions of the title and names text layers are linked to the Y position of the orange bar and offset by a specific amount (20 pixels above for the titles, 25 pixels below for the names).
Basically what I'm trying to come up with is the match to figure out, based on the height of the title text layer and the height of the names layer, how far from the center of the comp (960x540) I have to offset the orange bar to make everything center-aligned. I'm struggling with the math on this one though and
I'd be grateful for any help on either half of this!
Copy link to clipboard
Copied
This is where I found the expression if anyone's wondering:
https://lesterbanks.com/2019/07/how-to-get-true-text-layer-size-in-after-effects/
Copy link to clipboard
Copied
The comp center is just thisComp.width*0.5 and thisComp.height*0.5, respectively. nothing fancy there. Then you simply subtract the values from the position of the layer to get the differences you need to add elsewhere. The error you're getting is a copy & paste error from web page code. The minus is no actually a minus. Took me a proper text editor with syntaxc highlighting to figure that one out. Re-type it and it will work.
Mylenium
Copy link to clipboard
Copied
Mylenium, I don't think you understood what I was asking for. I know how to find the center of the comp. If you re-read my request, what I'm trying to do is align a series of elements to the center of the composition. I'm trying to figure out the center point to a series of elements, and then align them to thisComp.width/2 and thisComp.height/2. Does that make sense?
Copy link to clipboard
Copied
The most obvious problem I see is that there is no variable named "w" above the fifth line in your expression. The second problem is that finalSize only defines one dimension. I fixed those problems and still got the error. Then I re-typed the fourth line from scratch, and the error went away. Here's the expression:
targetLayer = thisComp.layer("Name Name Name Name");
h = targetLayer.sourceRectAtTime().height;
s = targetLayer.transform.scale[1];
p = (s - 100) * .01;
finalSize = p * h;
[finalSize, finalSize]
That code produces no usable data.
If you want to stack layers using sourceRectAtTime(), you need to tie in position, height, left, width, and scale efficiently.
The first layer in the stack has no position expression. The anchor point must be in the middle of the shape layer, and it should be a rectangle. Try adding this expression to each additional layer in the stack.
src=thisComp.layer(index - 1);
srcHeight = sRc.sourceRectAtTime().height / 2;
vPad = 0;
refScale = thisLayer.scale * .01;
box = thisLayer.sourceRectAtTime();
t = - box.top;
h = box.height / 2;
sRc.position + [0, (h + t) * refScale[1] + vPad + srcHeight]
Then animate the position of the first layer.
A much less labor-intensive workflow would be to create your end credits in Illustrator with precisely the format you want. Make the artboard tall enough to include all of the credits and artwork. Then import the AI file and animate the position using a simple expression to move the layer up a specific number of pixels on each frame to avoid judder and aliasing problems. A good rate for a credit roll is between 4 and 6 pixels per frame. Adding motion blur will smooth things out. Your end credits will be one AI layer, one expression, and, if needed, a background layer.
If you choose to use a stack of text and shape layers, you can use the same expression for an Illustrator layer. Try this:
moveDistance = 4;
startTime = time - thisLayer.inPoint;
frameCount = startTime / thisComp.frameDuration;
pixPerFrame = frameCount * moveDistance;
[value[0], value[1] - pixPerFrame];
I have done a lot of title rolls. Any roll or scroll that does not move precisely at a whole number of pixels will have aliasing and judder (strobing) issues with the edges of the type.
Laying out in AI, with their sophisticated type tools, converting the text to outlines takes only a few minutes if you already have a list of names and positions. Animating the rolling titles in AE takes about 2 minutes if you have saved the expression as an animation preset or saved the code. I usually render with an alpha channel and no background, then add the final title roll to a Premiere Pro timeline because that renders much faster and my end credits typically involve a lot of different background shots.
Copy link to clipboard
Copied
Great stuff Rick, many thanks for the share.
As it happens, I actually figured it out. The expression that does the trick is just one line long as it turns out:
thisComp.layer("Layer Name").sourceRectAtTime().height
thisComp.layer("Layer Name").sourceRectAtTime().width
And that's it! And the math to get everything vertically centered the way I wanted was easy too (this isn't the actual expression but it's a breakdown of what went into it):
Credit Bar Y position: (thisComp.height/2)-((pixel height of names layer - pixel height of titles layer)/2)
This centers it up in the exact center of the comp. It works because the name and title layers are equally distant from the bar; I'd have to add another offset if the two distances were different.
The Illustrator workflow wouldn't work for me because I need things that an AI can't provide:
* The ability to edit a master style for all of these and have it propagate everywhere without having to go through one by one (all of these are parented to a master template and they inherit text styles)
* The ability to adjust the distances from the bar for both the titles and names
I hear you loud and clear that it would be easier, but it wouldn't give me what I need.
Copy link to clipboard
Copied
I thought that this idea would make a good animation preset. As long as the Rectangle/Transform properties are at the default values, this expression corrects for scale and baseline shift for text layers and size of the spacing rectangle. You can position the top layer anywhere, and all layers will follow.
refPad = 20;
ref = thisComp.layer(index - 1);
refPos = ref.position;
refScale = ref.scale[1] * .01;
refBox = ref.sourceRectAtTime();
refTop = refBox.top;
refHeight = refBox.height;
refBtm = refPos[1] + (refTop + refHeight) * refScale + refPad;
lyrScale = thisLayer.scale[1] * .01;
lyrSize = thisLayer.sourceRectAtTime();
lTop = lyrSize.top;
lHeight = lyrSize.height;
lyrFix = (lTop + lHeight) * lyrScale;
[refPos[0], refBtm - lyrFix + (lHeight * lyrScale)]
Find more inspiration, events, and resources on the new Adobe Community
Explore Now