Auto Adjust Shape Layer Size Based on Text in After Effects

Поделиться
HTML-код
  • Опубликовано: 13 окт 2024
  • Learn how to auto adjust shape layer size based on text in after effects.
    In this quick After Effects tutorial, learn how to set up your shape layers to automatically adjust and re-size based on the your text.
    🔔 Subscribe for more tutorials: www.youtube.co...
    Social Media:
    Follow on Instagram: / motioncaddy
    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]

Комментарии • 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 9 месяцев назад +1

    thanks a ton: super helpful + concise!

  • @rebeckaz1734
    @rebeckaz1734 7 дней назад +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  5 дней назад

      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!

  • @IsionIndustries
    @IsionIndustries 8 месяцев назад

    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.

  • @sepinass9488
    @sepinass9488 11 месяцев назад

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

  • @erickamasteinberg3266
    @erickamasteinberg3266 5 месяцев назад

    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  4 месяца назад

      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 4 месяца назад

      @@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..

  • @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.

  • @lushprod
    @lushprod 11 месяцев назад

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

  • @dbrammelljr
    @dbrammelljr Год назад +1

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

    • @LongEarthTradingCompany
      @LongEarthTradingCompany 8 месяцев назад

      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 8 месяцев назад

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

  • @collinr811
    @collinr811 5 месяцев назад

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

    • @MotionCaddy
      @MotionCaddy  20 дней назад

      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.