4 Replies Latest reply on Jul 26, 2018 9:39 AM by Greg2BPro

    Font Size Expression

    Andrey Arkhipov Level 1

      I need an expression that would automatically change the font size based on how many characters are typed in.

       

      The goal is to fit multi-line text into a bounding box as it's read from the external text file.

       

      Does anyone know whether it's possible through an expression, or SDK by writing a plugin?  So far I was unable to find any info on this topic.

       

      Thanks for any ideas.

        • 1. Re: Font Size Expression
          Dan Ebberts Level 5

          Expressions don't have access to font size, but you could use an expression to scale the text. Expressions also don't have access to the bounds of a text layer (although there is a hack to detect it using a sampleImage() loop. You could base the scale on the number of characters in the text, if that's close enough. Scripting does have access to everything you'd need to automate this - but you'd have to run the script whenever you changed the text. I'm guessing you could do it with a plug-in, but the learning curve for the SDK is pretty steep.

           

          Dan

          1 person found this helpful
          • 2. Re: Font Size Expression
            jessek98883148 Level 1

            If you add a text animation property to the text you can totally alter it through expressions. It won't be by point size but you can adjust scale and tracking. Drop down arrow on the text, click the Animate arrow button and add any properties you need. Not perfect, but it works.

            1 person found this helpful
            • 3. Re: Font Size Expression
              maartenk28934659 Level 1

              sourceRectAtTime().width gives you the bounds. ( .width gives you the with, height the height)

               

              use this in expression scale:

               

              // always Title Save width HD

              x= 1920/thisLayer.sourceRectAtTime(time).width*80;;

              [x,x]

              • 4. Re: Font Size Expression
                Greg2BPro Level 1

                Long time since you posted this but i just wanted to say thanks!

                 

                This helped a lot. The only thing is I wish I could extend this to search the text multiple times to find different sets of numbers and adjust things. But that seems a bit above what expressions can do with the built in methods.