Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects incrementing numbers line by line

  • incrementing numbers line by line

     Nil Giles updated 11 hours ago 3 Members · 7 Posts
  • Nil Giles

    November 22, 2021 at 11:03 am

    hi im wondering if there is an expression to have numbers increment per line, for e.g:
    1
    2
    3…etc

    perhaps with a slider control so i can increase as desired.
    ive had a search but cant find anything suitable
    thanks ver much for your help

  • Kevin Camp

    November 22, 2021 at 11:55 pm

    Create an empty text layer, add a slider control and add this expression to the source text property:

    n = effect("Slider Control")("Slider") ;
    nums = '' ;
    for ( i = 1; i <= n; i++ ) {
    nums = nums + i + '\r';
    }
  • Nil Giles

    November 23, 2021 at 9:11 am

    Thanks so much for this.
    i’d like to understand second half of it so i dont have to keep asking people, maybe help others!
    is it shorthand code? i know im asking a lot but would you be able to briefly explain it?
    or point me in a direction where i can learn, understand or unpack this.
    thank you again!

  • Meng Zhiqun

    November 23, 2021 at 10:52 am

    Actually you don’t really need sliders for this.
    You can paste this expression into the source text and each line you enter will add an index in front of the line. Just make sure you start a new line with “enter” or “return”, not “shift+enter” or “shift+return” as the latter causes problems. Have fun!


    var valAry = value.split("\r");

    var curLine = "";

    for (var i=0;i<valAry.length;i++){

    curLine += i+1 + " " + valAry[i] +"\r";

    }

  • Meng Zhiqun

    November 23, 2021 at 11:12 am

    To explain the expression,
    “var valAry = value.split(“\r”);”
    This sets a variable name to the value.split(“\r”);

    “value”
    This is the property value, in this case, whatever text you enter.

    “value.split(“\r”);”
    This searches for any line breaks you have entered and split the value from a string to an Array.
    An array is like a group of objects and array indexing starts from 0 instead of 1.
    So if I have a basket of apples, the basket would be the Array, and the first apple would be basket[0], the second apple would be basket[1] and so on.

    “var curLine = “”;”
    This sets a variable name “curLine” and give it an empty string to be filled later.

    “for (var i=0;i<valAry.length;i++){
    //something
    }”
    This is generally called a for loop which I will break down more in the bottom.

    “var i = 0;”
    It sets a variable “i” to be 0. 0 because array indexing starts from 0.

    “i<valAry.length; i++”
    This sets valAry.length as the total number of loops to be done.
    for example, if your text has 2 lines, valAry.length would be 2, so if i starts from 0, it would finish the loop and see if it is still smaller than valAry.length. If it is smaller, i ++ plays out and i becomes 1 now and loops again..

    “curLine += i+1 + ” ” + valAry[i] +”\r”;”
    This sets the string for the variable “curLine” which was set earlier.
    Since i starts from 0 and I would like the first line to start from 1 instead, I added a i+1.
    valAry [i] is each line of text before each line break.
    “\r” is the line break.

    I hope this helps you understand things more! 🙂

  • Kevin Camp

    November 23, 2021 at 7:46 pm

    If you’re looking to learn more on expressions, there are several links to help you get started here: https://motionarray.com/learn/after-effects/getting-started-with-after-effects-expressions/

    motionscript.com has been around for a while and is one that I used a lot when learning expressions.

    Also, the second part of the first expression (the For loop) is really just javascript, so you can find a lot on the web for that. Here’s a link on w3schools that discusses For loops: https://www.w3schools.com/java/java_for_loop.asp

  • Nil Giles

    November 26, 2021 at 12:05 pm

    thanks so much for your reply, extremely helpful to have an understanding of what is going on, your breakdown has made it a lot less daunting and makes me want to learn more! thanks so much!!

    I will follow the links posted

Viewing 1 - 7 of 7 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy