5 Replies Latest reply on Sep 17, 2009 2:40 AM by Andy Bay

    Simple index expression math

    Andy Bay Level 1

      I have to be honest here: I really suck at math


      How would you guys approach a task like this:


      I'm trying to create a comp that holds 20 names stacked below each other on the Y axis. Now I'm looking for an expression that could automatically spread the distance between the names, if I delete some of these names (which are just simple text layers).


      I realize I need to use the "index" expression to drive this but I have no idea on how to approach the rest of the math. Any tips will be appreciated!

        • 1. Re: Simple index expression math
          Rick Gerard Adobe Community Professional & MVP

          This is actually quite simple. Just multiply the offset value in pixels by the index and add it to the current position of y.


          The expression looks like this:


          x = value[0];
          y = value[1];
          offset = 20; // offset in pixels
          newy = y + (index * offset); 
          [x, newy]



          1. First you get the current value for X and Y
          2. Then you set a value for the offset. In this case 20 pixels
          3. Then you get the new y position by adding the current Y value to the index times the offset
          4. Finally you put these values in an array enclosed in brackets. If you are working in 3D space you'll also need to define and place in the array a value for Z


          If you wanted to animate the space between layers I'd add a null to the bottom of the stack, add an expression control slider to the null, and then change the third line of the expression to:



          offset = thisComp.layer("Null 1").effect("Slider Control")("Slider"); // offset in pixels


          Then apply this expression to any of the text layers (or any other kind of layer) and select position and go to Edit>Copy Expression only. Then select all other layers you want to offset and paste. Badda bing – you're done.
          • 2. Re: Simple index expression math
            Andy Bay Level 1

            It does help, thank you very much!

            • 3. Re: Simple index expression math
              Andy Bay Level 1

              Damn, I just had the chance to test this and the expression (though helpfull) doesn't do what I'd need :S


              I think I didn't explain myself well enough! What I'm looking for is an expression that would sread the layers evenly to the comp according to how many layers there are in total. So if there was just two layers, I would like them to be spread out so that there is equal amount of space between the top and bottom of the comp and those two layers. In other words the layers would always be centered and evenly spread on the y-axis of the comp, no matter how many layers there were! Maybe it gets harder..?


              Any additional help will be appreciated greatly!

              • 4. Re: Simple index expression math
                Mylenium Most Valuable Participant



                1 person found this helpful
                • 5. Re: Simple index expression math
                  Andy Bay Level 1

                  Thanks Mylenium, you're the Man!