Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Text Scale Expression Is Not Working

Explorer ,
Oct 07, 2017 Oct 07, 2017

Dear All

I need to adjust the scale of each letter to the text length, in such a way that if I add letters to my text the size reduces. 

Weirdly the expression I wrote is working at any other property but not on the scale (the values of the scale are changing by adding letters, but the visual is not changing, as you see the values are 0 but the text is still visible with the scale of 100).

There is a picture of my workflow down here:

Thanks thousand times.

3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 07, 2017 Oct 07, 2017

maybe this:

l = text.sourceText.length;

lmax = 10 // maximum letters

lmin = 0 // minimum letters

smax = 100 // maximum scale

smin = 20 // minimum scale

s = linear(l, 0, lmax, smax, smin);

[s,s]

Translate
Explorer ,
Oct 07, 2017 Oct 07, 2017

and here is the range selector setting:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2017 Oct 07, 2017

maybe this:

l = text.sourceText.length;

lmax = 10 // maximum letters

lmin = 0 // minimum letters

smax = 100 // maximum scale

smin = 20 // minimum scale

s = linear(l, 0, lmax, smax, smin);

[s,s]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2017 Oct 07, 2017

The reason that the text is not scaling is the range selector setting. Try setting

Your sourceRecAtTime method gives you the width of the text that is entered. Adding a text animator for scale is going to change the scale of the individual letters but not the width of the text unless you animate the kerning. Without the expression just add a scale animator and change the X scale to 20%. You'll get this:

Screen Shot 2017-10-07 at 10.00.22 AM.png

SourceRecAtTime will change when you change kerning or when you add characters but it's not going to work for your application. As Roei suggested you need to be counting characters.

To set up an expression that will work you first have to set up a ratio between the standard number of characters and the line length you want. You can measure the line using guides. Let's say your standard line had 27 characters and a length of 1000 pixels. To determine the length ratio you have to just define those values and then count the characters in your layer and do some division:

lineLength = 1000;

standardNumCharacters = 27

numChar = text.sourceText.length;

lengthRatio = 100 * standardNumCharacters / numChar;

This will give you a value of 100 as the length ratio when you have 27 characters in the line. You can adjust the font size and tracking to make the layer exactly the length you want it to be. You can just use this expression for scale by adding x = to the last line and then completing the array like this [x. 100]

If you apply the expression to a Scale animator you will also have to work on kerning because letters are scaled individually. It would be a lot simpler just to apply the expression to the text layer's scale property.

Your line won't stay exactly the same length unless you use a monospaced font because and "I" is not nearly as wide as a "w" but it should get you pretty close.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2017 Oct 07, 2017

Hi Rick Thanks. there's a line of code that's not being used:  "lineLength = 1000".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2017 Oct 07, 2017

You are right. That's what I get for writing expressions without having AE open. I will take a look as soon as I can but come to think of it, unless you are using a monospaced font it's not gong to be 100% accurate anyway. Just simply using the ratio of the standard number of characters and the actual number of characters is probably close enough. Throwing line length in may make it a little more accurate though.

Edit: Palm slaps forehead. Turns out you can use sourceRecAtTime() and eliminate the problems with regular fonts. Note:You don't need all the gobbledygook in the parenthesis if you are not changing anything. Just divide the actual text length from the sourceRecAtTime method the desired layer length and you have the right scale factor. Just multiply x by 100 to turn it into a percentage. Apply this to scale and all you have to do is set the target length for your text layer. There is still a little space at the start and end of the characters but the overall size doesn't change a bit. You can get rid of the discrepancy by subtracting about 10 pixels from the width.

textLen = sourceRectAtTime().width - 10;

targetLen = 800;

  x = targetLen/textLen;

[x*100, value[1]]

I thought this was a good enough idea that I added an Expression Control>Slider and  created an animation preset that I'm willing to share:

Constant Width Text.ffx

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 07, 2017 Oct 07, 2017

Thanks Rick

your explanation was awesome, and the presets was even more helpful.  Roei's answer however, with a little bit of tweak and adjust the tracking, suite my situation better.

both methods are pretty interesting.

thumbs up

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2017 Oct 07, 2017

Please show us what you used eventually, this may be useful for others too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 07, 2017 Oct 07, 2017

Sure, I'm trying to make a typography template. I will share the link here once it finished.

btw

I found the first issue that didn't allow my expression to work, apparently I can't use the command "sourceRectAtTime()" at text menu on the same text layer. There should be some middle object to read the source Rect, and then I read it again from that middle object.   

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 08, 2017 Oct 08, 2017
LATEST

This is the way I could use sourceRectTime instead of length, so the tracking is a bit improved (text_02 is the middle object):

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines