Skip to main content
Inspiring
June 13, 2013
Answered

Rounding text size to nearest whole number?

  • June 13, 2013
  • 1 reply
  • 2233 views

I've had to rescale some artwork, but now I'm left with type sizes that are 71.68px tall, 34.51px tall, etc.

Is there a script that'll snap all the text in a document to it's nearest whole number or 0.1 decimal?

This topic has been closed for replies.
Correct answer Larry G. Schneider

I don't know how to make it affect every text object in my doc (or every selected text object).


// rounds the size of text in all textFrames in your document

var aTFrame = app.activeDocument.textFrames;

for ( i = 0; i < aTFrame.length; i++ )

{

var fractionSize = aTFrame.textRange.characterAttributes.size;

var RoundedSize = Math.round(fractionSize);

aTFrame.textRange.characterAttributes.size = RoundedSize;

}

redraw();

This will do all the text frames. Copy the above, paste it into a text editor or the Adobe ESTK (ExtendScript Tool Kit) and save as a plain text file with a .jsx extension. Place it into Applications/Adobe Illustrator CSX/Presets/en_US/Scripts folder and restart AI. Run it by having a document open in AI and call it from File>Scripts>scriptname.

1 reply

pixxxelschubser
Community Expert
Community Expert
June 13, 2013

something like this?

// rounds the size of text in first textFrame in your document

var aTFrame = app.activeDocument.textFrames;

var fractionSize = aTFrame[0].textRange.characterAttributes.size;

var RoundedSize = Math.round(fractionSize);

aTFrame[0].textRange.characterAttributes.size = RoundedSize;

redraw();

It's missing only unlock all layers and so on … and a loop through all text frames. Can you make this by yourself?

Inspiring
June 16, 2013

I'm sorry, I know diddly about scripting in Illustrator.

pixxxelschubser
Community Expert
Community Expert
June 17, 2013

Have you tested the script or do you not know how to use it? (This script part rounds only the character size of the first text frame in an open Document.)