Copy link to clipboard
Copied
I'm using a plugin called CompsFromSpreadsheet to automatically create a bunch of compositions from a template, with as little editing as possible. I want to set one of my object layers to move up or down depending on how many lines are in the text layer above, so there will always be the same distance between the last line of text and the object regardless of how long the paragraph is. Is this possible?
Same idea. Show me the timeline with the and I can probably help you out. It looks like you have drawn a Paragraph Bounding Box with your text tool. When you do that the Anchor Point moves to the center of the PBB. It is important to know that. the sourceRectAtTime() method does not respect the PBB but unless you really want to go nuts with the expression the easiest thing to do is just create a simple expression that looks at the text layer, reads the text layer position, reads the height of th
...Copy link to clipboard
Copied
the sourceRecAtTime() method returns x and y dimensions of the text layer including descenders. You can use that dimension array in combination with the comp height and comp width to adjust the relative position of the text layer. I would have to see a screenshot of the text layer with the modified properties of all parameters included to write the expression for you but you should be able to do it yourself if you have a decent understanding of comp space and layer space. [thisComp.width/2, thisComp.height/2] will give you the comp center. Unless you are moving the anchor point or fiddling with baseline shift you should be able to just subtract the Y (value[1]) value from sourceRecAtTime() to center up the text layer in the comp panel, then figure out what the difference is between the total height and the bottom and throw in that value to put the bottom of the last line where you want it to be.
If you can't get that to work with the script, you can create an animation preset and apply that after the comp has been created.
Copy link to clipboard
Copied
Thanks Rick, I'm pretty new to expressions but it sounds like you're suggesting moving the text layer... actually I want the text layer to stay where it is, and just the object layer underneath to move up or down relative to the amount of text inside it. The text layer has Opacity keyframes, the object layer has Scale keyframes. See example below – since this product has a short name that only needs one line of text, I would like the "Only in Pharmacy" logo to move up a bit so there's not so much gap.
Copy link to clipboard
Copied
Same idea. Show me the timeline with the and I can probably help you out. It looks like you have drawn a Paragraph Bounding Box with your text tool. When you do that the Anchor Point moves to the center of the PBB. It is important to know that. the sourceRectAtTime() method does not respect the PBB but unless you really want to go nuts with the expression the easiest thing to do is just create a simple expression that looks at the text layer, reads the text layer position, reads the height of the text layer (including descenders) and then adds the text rectangle's height to the Y position of the Graphic layer. To avoid layer naming problems with expressions if you always put the text layer just below the graphic you can use index + 1 to find that layer instead of using the layer name. A simple expression to keep the graphic aligned with the bottom of the text area looks like this:
st = thisComp.layer(index + 1);
sh = st.sourceRectAtTime().height;
tp = st.position;
np = [value[0], tp[1] + sh]
st = the text layer just below the graphic layer
sh = the text layer height as defined by sourceRectAtTime()
tp = the text layer's position
The math is all done inside the XY array in the last line of the expression:
np = the original value of X for the layer, then the Y position of the text layer (st) plus the height of the text.
You can easily manually align the graphic layer in X and use the baseline shift in the Character Panel or the Anchor Point to fine-tune the Y position. Unless you want to manually adjust the baseline shift in the character panel for layers text that has descenders you'll have to just pick a value that works and let the expression position the graphic (the box of pills)
If your comp is more complex than I think then I really need to see a screenshot to figure out the expression. If you want everything to be automatic you will have to consider the anchor point of both layers, the size of the graphic layer, and make the appropriate calculations.
Copy link to clipboard
Copied
Thanks Rick, that works perfectly!
Copy link to clipboard
Copied
Can this be applied in the X axis as well? When I attempt to swap width for height, and the array to call to the position from the X dimension, my graphic layer still moves in the Y.
st = thisComp.layer(index + 1);
sw = st.sourceRectAtTime().width;
tp = st.position;
np = [tp[1],value[0] + sw]
Copy link to clipboard
Copied
Does anyone have figured it out for X axis as well ?
Copy link to clipboard
Copied
The last line in your expression is not quite right, the following expression works for me to align a layer next to your text on the X-axis:
st = thisComp.layer(index + 1);
sw = st.sourceRectAtTime().width;
tp = st.position;
np = [tp[0] + sw, value[1]]