7 Replies Latest reply on Jan 10, 2013 8:38 AM by CenekStrichel

    Get number of lines by expression

    CenekStrichel Level 1

      Hello I can easily find number of characters in text by text.sourceText.length; command. But I need number of lines. Is it possible? I can not find any documentation about text.sourceText. next parametrs. It will inherited from javascript I think.

       

      Thanks

        • 1. Re: Get number of lines by expression
          Mylenium Most Valuable Participant

          The hard way would be to count the line breaks in a loop, the simple way would be to apply a text selector with mode set to lines and link the Start/End values to wherever you need them...

           

          Mylenium

          • 2. Re: Get number of lines by expression
            CenekStrichel Level 1

            Thanks for tip. I used Range Selector with setted Lines, but what now? How can I find how many lines have my text?

            • 3. Re: Get number of lines by expression
              Mylenium Most Valuable Participant

              Set the mode to Index and the End value will reflect the number of lines.

               

              Mylenium

              • 4. Re: Get number of lines by expression
                chauffeurdevan Level 2

                if you use it as and expression on the sourceText of the layer with the text : value.split(/\n|\r/).length

                 

                on a different layer targeting a text layer called myTextLayer : thisComp.layer("myTextLayer").text.sourceText.split(/\n|\r/).length

                • 5. Re: Get number of lines by expression
                  CenekStrichel Level 1

                  Thanks, it is really close what I need, but it detect only if I press Enter and do next line. But I need check number of lines, but lines which made After Effect automaticly when I write without Enter. My question was not exact, so sorry.

                   

                  All story: I read many text from external file to After Effect, then I load this different long text to text object in AE. But AE can not center text verticaly (if yes, it will solve my problem) so I need check number of lines, which was generated by After Effect. No Enter was pressed. When I will have number of lines, I can change position Y and text will be aligned inside my graphic. Text in readed file is in one line. But different count of characters. Maybe it is not possible check automatic lining ...

                   

                  Method with Range Selection is not working in this case. It is true, that it write number of lines, but when I read another text from file, it hold same value.

                   

                  Sorry for my english

                  • 6. Re: Get number of lines by expression
                    Mylenium Most Valuable Participant

                    There is no way to do this with expressions. Only scripts can read area text shape size and other font properties, but even then you need to input some values into your formula manually, because naturally the visible content of a font is different from the em box of the letters and other specifics like glyph substitution, custom baseline settings and whatnot may matter.

                     

                    Mylenium

                    • 7. Re: Get number of lines by expression
                      CenekStrichel Level 1

                      I try just add \n to my input text and it is working great with thisComp.layer("myTextLayer").text.sourceText.split(/\n|\r/).length

                      so when I synchronize my graphic, with input formular (width) it will works, thank you guys!