Set Anchor Point Dynamically in After Effects - Learn AE Expressions

Поділитися
Вставка
  • Опубліковано 10 лип 2024
  • This Adobe After Effects tutorial explains in detail how to apply expressions for anchor point and position. This technique enables to dynamically readjust layers placement in the composition based on content size, using sourceRectAtTime. This is super helpful if you want to update data in the project with an ease.
    Change content in the project dynamically without any UI interaction or just increase your own workflow efficiency.
    #aftereffects #expressions #sourcerectattime #anchorpoint
    If you want to learn techniques about motion design, expressions and scripting in AE - you are in the right place.
    Follow me to be up to date with whats going to happen next:
    www.tom10.co/tutorials
    / tom10ae
    / tom10videos

КОМЕНТАРІ • 51

  • @irfankhaleel4439
    @irfankhaleel4439 4 роки тому +37

    layerBound=thisLayer.sourceRectAtTime(time);
    T=layerBound.top;
    L=layerBound.left;
    W=layerBound.width;
    H=layerBound.height;
    [L+W/2,T+H/2]

    •  4 роки тому +2

      The hero we need

    • @Tom10
      @Tom10  3 роки тому +5

      Thanks, Irfan! ​@ Its always easier to just copy paste, but however - it won't give you any good without actually writing it, long term ! :)

    • @bubyoz
      @bubyoz 5 місяців тому

      // Get the bounds of the layer at the current time
      layerBound = thisLayer.sourceRectAtTime(time);
      // Calculate the center point of the layer bounds
      centerX = layerBound.left + layerBound.width / 2;
      centerY = layerBound.top + layerBound.height / 2;
      // Return the center point as an array [x, y]
      [centerX, centerY];

  • @ina4148
    @ina4148 22 дні тому

    This is awesome. I like that you took the time to explain what each expression does. This is probably the most useful expression manual I have seen.

    • @Tom10
      @Tom10  21 день тому +1

      Thanks a ton! Where usually, people just scrub to the timeframe where expression is, copy it and move on, haha! Copying helps 1 time, understanding what you are copying to - N times :)

  • @sfnadim
    @sfnadim 3 роки тому +2

    I really love this expression, thanks

  • @natevplas
    @natevplas 5 років тому

    Thanks! This is really useful!

  • @MarcVilarnau
    @MarcVilarnau 3 роки тому +1

    Thanks a lot, this was really helpful!

    • @Tom10
      @Tom10  3 роки тому

      Glad it was useful, Marc!

  • @steliosnikolaou2738
    @steliosnikolaou2738 3 роки тому +1

    Thanks man, never knew about this!

    • @Tom10
      @Tom10  3 роки тому

      Cheers, matte! In case you are looking for more auto-updating dynamic features, check this one as well. : ua-cam.com/video/XPWvy2kff8A/v-deo.html
      its about assets scaling in the comp.

  • @AlessioRissato
    @AlessioRissato 4 роки тому

    Excelent Tom!
    thanks for the learning

    • @Tom10
      @Tom10  4 роки тому +1

      Thank you a lot, Alessio!

  • @koraynergiz
    @koraynergiz 9 місяців тому

    It was very useful for a job I wanted to do, thank you very much

    • @Tom10
      @Tom10  9 місяців тому

      You are welcome, glad it helped!!

  • @ambrosioflavio2266
    @ambrosioflavio2266 3 роки тому +1

    thanks!

  • @sanalsubramanian4639
    @sanalsubramanian4639 2 роки тому +1

    Thanks champ 🌹

  • @Palabow
    @Palabow 3 роки тому

    u are awesome!!!

  • @lakshitasharma5843
    @lakshitasharma5843 3 роки тому +2

    THANK YOU SO MUCHH!!
    (I struggled for 2 hours :/ )

    • @Tom10
      @Tom10  3 роки тому

      Glad to know it helped! 🤩

    • @carolynscott7733
      @carolynscott7733 3 роки тому

      Have you trapcode pack ?

  • @impy1980
    @impy1980 3 роки тому +2

    Thanks, I was really struggling, I have a text box that moves up as a new line of text is entered so the bottom line always stays in the same position, and the shape layer behind scales out height and width to match. I finally got my lower thirds to work after experimenting on and off over a few months, it worked perfectly, until I discovered if I changed the text font type or size then the position slewed slightly up and right, which then visually separated the shape layer from the 2 other animated static "prettification" elements I have, and I couldn't find a a way to anchor the text to scale from the absolute bottom left. It turned out to be a combination of no expression in the text anchor point, and removing an expression from the text position.
    Thanks for this easy fix, as as well as a little experimenting on my part I have my lower third auto adjust just as how I envisaged a long time ago, I'd been manually adjusting keyframes. I'm far from an AE expert and especially expressions/coding/maths, I'm just good at reverse engineering and problem solving. This video deserves more likes.

    • @Tom10
      @Tom10  3 роки тому +1

      Hey Mark, thanks for covering it briefly! This video is just an initial boilerplate to start your expressions rigging - by linking expressions with other layers, a whole lot more can be achieved. Which, you have successfully made on your own, well done!

  • @swarajemaratha
    @swarajemaratha 3 роки тому

    its very much useful bro...
    when u have to kept the text bottom aligned and the number of lines keeps changing if its a template.
    may be those 4 guys who disliked might not knowing what their problem is n how to follow ur instructions..

    • @Tom10
      @Tom10  3 роки тому +1

      Thanks, man! Its always a learning curve - it never gets easier, you just start solving more complex tasks ✌🏻keep it up !

  • @jesuisparpaing
    @jesuisparpaing 2 роки тому

    Hello!
    I've been trying to setup my object in the middle of the screen as shown in the second part of the video,
    but because I set up my anchor point to always be on the left, when my position expression is applied, it centers my object according to the anchor pointand so it is offset.
    I tried reapplying the values from first script into the position one so that I could use [W-WC/2, HC/2] (where WC and HC are comp's width and height) but it doesnt quite work.
    Is there a way to do it or do I need my anchor point to always be centered for my position to be centered too ?

    • @jesuisparpaing
      @jesuisparpaing 2 роки тому

      I figured it out!
      the solution was this:
      layerBound = thisLayer.sourceRectAtTime(time);
      W = layerBound.width;
      WC = thisComp.width;
      HC = thisComp.height;
      [WC/2-W/2,HC/2]

    • @Tom10
      @Tom10  2 роки тому

      @@jesuisparpaing well done! And thanks for taking time to share it with others - its much appreciated!

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

    ❤❤❤

  • @GGMOBBIN
    @GGMOBBIN 3 роки тому +2

    This is extremely useful and efficient! Thank you!
    I've been struggling to find a solution to this problem. I can't seem to wrap my head around it.
    I have two text layers next to each other both left aligned. The second text layer is contained within two parentheses shape layers like so:
    TextLayer1 ( TextLayer2 )
    How do I apply these expressions so that the positions of TextLayer1 and TextLayer2 including the parentheses dynamically re-adjust no matter what I type in?
    Thanks ( ThanksAgain )

    • @Tom10
      @Tom10  3 роки тому +1

      Hey! I would suggest you to do the following, to make it easier for you:
      1. Keep one main layer for your phrase (left aligned)
      2. Create a new layer, which will define whats going to be inside parentheses. Set it a a guide layer (it won't be rendered, but still visible in viewport in that comp)
      3. In the main layer, write expression as follows:
      text.sourceText + " (" + thisComp.layer("YOUR 2nd LAYER NAME").text.sourceText + ")"
      Otherwise, you will have to deal with additional hurdles, like position readjustment when TextLayer1 length changes - just a redundant tedious thing. Let me know if that works!

    • @GGMOBBIN
      @GGMOBBIN 3 роки тому +1

      ​@@Tom10 This works and is precisely the simplified solution I was hoping to find (thanks!), however it only solves 95% of my issue. There are two other things I failed to mention earlier and that is TextLayer2 with parentheses are the same color but a different color than TextLayer1. The font I'm using also doesn't center the parentheses vertically so I have to shift the baseline of the parentheses up a few px but idk how to do that within expression - you see where I'm going with this. This is why I mentioned having two parentheses shape layers earlier. I'm curious if there are another few steps to your simplified solution that account for these annoying setbacks.

    • @Tom10
      @Tom10  3 роки тому +1

      @@GGMOBBIN Ahh, I see. It might be possible to merge multiple font styles in a single expression as well - but again, not very handy.
      Here is approach I suggest using alternatively.
      1. Make both layers however you need them to be, visual wise.
      2. Set both layers expression to attach anchor on the left side.
      3. Add this expression to the position of second layer (with parentheses)
      var refPosX = thisComp.layer("1").transform.position[0];
      var refPosY = thisComp.layer("1").transform.position[1];
      var refS = thisComp.layer("1").transform.scale[0] / 100;
      var xPad = 20;
      var yPad = 5;
      var refSize = thisComp.layer("1").sourceRectAtTime(time,true);
      var x = refPosX + refSize.width * refS + xPad;
      var y = refPosY + yPad;
      [x,y]
      Where xPad is gap between words and yPad is that baseline shift, and layer named "1" is a reference to your TextLayer1. You can attach them to a slider for additional controls.
      But keep in mind, that anytime first text layer will have letters with baseline legs, the baseline will be thrown off by that yPad.

    • @GGMOBBIN
      @GGMOBBIN 3 роки тому +1

      @@Tom10 I will provide an update as soon as I get a chance to test this out.

    • @GGMOBBIN
      @GGMOBBIN 3 роки тому +1

      I can't thank you enough. I wasn't expecting a reply this soon or as in-depth as the one you've provided. Learning stuff like this is making me realize I've been approaching animation wrong all along. I've been hesitant to get into expressions because it looks so daunting but it streamlines so many tasks. Amazing!

  • @marshalhembram3651
    @marshalhembram3651 3 роки тому

    What if I want to animate text's position?
    Please help

    • @Tom10
      @Tom10  3 роки тому +1

      Hey Marshal, the best way to do this is to pre-compose text and then do any manipulations if needed. If this is not possible to do, then try either to apply "Transform" effect and move text around, or parent it to the null.

    • @marshalhembram3651
      @marshalhembram3651 3 роки тому +1

      @@Tom10 Thanks brother, for the suggestion (y)

  • @andrestafur7980
    @andrestafur7980 2 роки тому

    Man, that's awesome, but I need some help… So... I am morphing stuff, so I need the anchor point to be always locked at the center of the layer. I tried the expression and it works properly with certain layers, but it doesn't work in others. Can you please tell me why? or what am I doing wrong?

    • @Tom10
      @Tom10  2 роки тому +1

      Hey Andres! Can you point out on what type of layers it fails to work? It might help!

    • @andrestafur7980
      @andrestafur7980 2 роки тому

      @@Tom10 It's a shape layer, it has shape keyframes so it is constantly changing its layer sizes, I wonder why it works in some layers but it just doesn't in others

    • @andrestafur7980
      @andrestafur7980 2 роки тому

      @@Tom10 Help, I figured out what the problem is: the layers I am working on don't start at the beginning of the composition, the expression works perfectly but the part of "time" is not. Is there any expression I could add to that so it is not delayed?

    • @Tom10
      @Tom10  2 роки тому

      @@andrestafur7980 with custom shape layers it might be a different story, but normally - the edge which remains closest to the edge you are pinning it to - even if it is animated !

    • @Tom10
      @Tom10  2 роки тому

      @@andrestafur7980 instead of time, try to set it to "time - thisComp.layer(YOUR SHAPE LAYER NAME IN BRACKETS).inPoint"

  • @InfernoGamingx
    @InfernoGamingx 5 років тому

    Hey Mate Can u make me a intro i could pay if it's exactly what I want lol?

    • @Tom10
      @Tom10  5 років тому

      Hey, feel free to contact me at tomas@boomframes.com to discuss potential approaches!