Auto Adjust Shape Layer Size Based on Text in After Effects

Поділитися
Вставка
  • Опубліковано 2 гру 2024

КОМЕНТАРІ • 19

  • @MotionCaddy
    @MotionCaddy  Рік тому +4

    Expressions:
    //size
    margin = 50;
    w = (thisComp.layer("TEXT").sourceRectAtTime().width)+margin*2;
    h = (thisComp.layer("TEXT").sourceRectAtTime().height)+margin*2;
    [w, h]
    //left text position
    content("Rectangle 1").content("Rectangle Path 1").size/2
    //right text position
    content("Rectangle 1").content("Rectangle Path 1").size/-2
    //centred text position
    margin = 50;
    w = (thisComp.layer("TEXT").sourceRectAtTime().width) + margin * 2;
    h = (thisComp.layer("TEXT").sourceRectAtTime().height) + margin * 2;
    x = thisComp.layer("TEXT").transform.position[0]; // Centered on the text layer
    y = thisComp.layer("TEXT").transform.position[1] + h / 2; // Adjusting Y to move downwards
    [x, y]

    • @motionsweeney
      @motionsweeney Рік тому

      This is super helpful.Thank you so much! I have a question: Is there a way to put in different margins? E.g. Top and Bottom have the same and left and right are different?

  • @cmsb217
    @cmsb217 10 місяців тому +1

    thanks a ton: super helpful + concise!

  • @sepinass9488
    @sepinass9488 Рік тому

    thanks very much for this man, if i want to have a separate shape for each line what should i do? please 🙏

  • @IsionIndustries
    @IsionIndustries 10 місяців тому

    First-time viewer! Nice flow of explanation. Question: Is there a way I can type paragraph text that fits within a box and is all neatly aligned? . Right now I just type out text and hit enter and some character lines are longer than others so it makes it more disorganize and unbalanced.

  • @erickamasteinberg3266
    @erickamasteinberg3266 6 місяців тому

    Great tutorial! How would the expressions be if I only want the width of the box to adjust with the text, but not the height? The reason is I'm creating a template for lower thirds, and I don't want the height of the box to change when there are letters that go lower, like g, j, etc. I basically want the height of the box to stay constant.

    • @MotionCaddy
      @MotionCaddy  6 місяців тому +1

      In this case you would need to change the expression in the size property.
      Try the below, which will use the current value you have set for the shape layer's height, which you can adjust to your preferred size:
      margin = 50;
      w = (thisComp.layer("TEXT").sourceRectAtTime().width)+margin*2;
      h = value[1];
      [w, h]

    • @erickamasteinberg3266
      @erickamasteinberg3266 6 місяців тому

      @@MotionCaddy Thanks for your reply! I'm still struggling to make this work. The original expression for the box size was:
      margin = 20;
      text_width = thisComp.layer("Text").sourceRectAtTime().width;
      text_height = thisComp.layer("Text").sourceRectAtTime().height;
      box_width = text_width + margin*9;
      box_height = text_height + margin*2;
      [box_width, box_height]
      Is that the expression I need to replace with the one in your reply? I tried, but the box still shifts..

  • @lushprod
    @lushprod Рік тому

    can you animate the size of the text and then the shapes follow the size of the letters?

  • @rebeckaz1734
    @rebeckaz1734 Місяць тому +1

    I can't get it to work with multiple rows. It doesn't expand equally on top and bottom. The ancor point remains on the first row (I think this is the problem) is there a fix for that?

    • @MotionCaddy
      @MotionCaddy  Місяць тому

      Thank you for pointing this out! It took a bit of time, but I figured out that I missed an expression needed in the shape layer's position when the text is center-aligned. Here’s the updated expression to put in the Position property of your shape layer:
      margin = 50;
      w = (thisComp.layer("TEXT").sourceRectAtTime().width) + margin * 2;
      h = (thisComp.layer("TEXT").sourceRectAtTime().height) + margin * 2;
      x = thisComp.layer("TEXT").transform.position[0]; // Centered on the text layer
      y = thisComp.layer("TEXT").transform.position[1] + h / 2; // Adjusting Y to move downwards
      [x, y]
      This adjustment should help keep the shape layer expanding downward as you add new lines. If you have any more questions, feel free to ask!

  • @marinabuchneva7841
    @marinabuchneva7841 Рік тому

    Thank you, very useful video🔥❤ I have a question: if we want to duplicate the text and the shape layer, the expression needs to be rewritten every time, but is there a way to duplicate the layers so that you don't have to change the expression every time?

    • @hoozn
      @hoozn Рік тому

      Use thisComp.layer(index-1)... instead of the layer name.
      That way, the sizing information is taken from the layer directly above the one that uses the expression (e.g. if the expression is used in layer 2, it takes the layer with index 2 - 1 as the reference).
      Then all you have to do is keep the corresponding text & shape layers in the correct order. i.e. Box 1's layer has to be directly below Text 1's layer in the timeline. If there is another layer in between those two layers, it does not work.

  • @dbrammelljr
    @dbrammelljr Рік тому +1

    How can I modify this expression so it only adjusts the shape's width and not height?

    • @LongEarthTradingCompany
      @LongEarthTradingCompany 10 місяців тому

      Yeah, this. I quickly found that if you have lowercase text with descenders (or not) it reshapes the box accordingly. But I of course want the same height regardless of which letters I input...

    • @LongEarthTradingCompany
      @LongEarthTradingCompany 10 місяців тому

      Aaaand I found out myself... Just change the value for "h" to a set value, like so: "h = 100;" for example

  • @collinr811
    @collinr811 6 місяців тому

    was wondering if this can be exported as a MOGRT file?

    • @MotionCaddy
      @MotionCaddy  2 місяці тому

      I haven't done this myself but I believe the answer is yes, you can export this as a MOGRT file. You’ll need to make sure the expression is fully compatible with Essential Graphics. Just add the controls you want to adjust (like text or shape properties) to the Essential Graphics panel, then export it as a MOGRT.