• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Adjusting layer position relative to text layer

Explorer ,
Dec 02, 2019 Dec 02, 2019

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?

TOPICS
How to

Views

6.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 03, 2019 Dec 03, 2019

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

...

Votes

Translate

Translate
Community Expert ,
Dec 02, 2019 Dec 02, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 02, 2019 Dec 02, 2019

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.

 

Screen Shot 2019-12-03 at 12.51.01 PM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 03, 2019 Dec 03, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 03, 2019 Dec 03, 2019

Copy link to clipboard

Copied

Thanks Rick, that works perfectly!

 

Screenshot.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2023 Apr 27, 2023

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]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 09, 2023 Aug 09, 2023

Copy link to clipboard

Copied

Does anyone have figured it out for X axis as well ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

LATEST

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]]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines