Forced change of paragraph properties

AiScripts
2 min readJul 7, 2022

Use the paragraphAttributes properties to control the values in the Paragraph panel: alignment, space between paragraphs, indentation from left and right edges.

Problem

There are script bugs in Illustrator:

  • firstLineIndent, leftIndent, rightIndent, spaceBefore, spaceAfter are not zeroed;
  • the justification property is not switched to left-alignment.
var str = activeDocument.textFrames[0].paragraphs[0];
str.paragraphAttributes.firstLineIndent = 20;
Zeroing the indent bug

Solution

At the end of the demo, I scaled the text and the indentation zeroing worked. Changing the font size and other attributes in the Character panel won’t reset the bugs in the Paragraph panel. Temporary scaling can be added to the script.

var str = activeDocument.textFrames[0];
str.resize(200, 200); // Uniform scale to 200%
str.paragraphs[0].paragraphAttributes.firstLineIndent = 0;
str.resize(50, 50); // Uniform scale to 50%
Bug fix

It also helps to change the Align before changing the indentation. But if the text was aligned to the left edge, we get a second bug when the script doesn’t assign back Justification.Left.

You can also change several numeric paragraph properties in the script at once, then the first of them will reset. But then we get a bug in another property. The scaling trick is safer.

Align left fix

Similarly, you can make a working switching of alignment to the left edge (justification). Remember the position of the object beforehand.

var str = activeDocument.textFrames[0];
var pos = str.position;
str.resize(200, 200); // Uniform scale to 200%
str.story.textRange.justification = Justification.LEFT;
str.resize(50, 50); // Uniform scale to 50%
str.position = pos;

--

--

AiScripts

Sergey Osokin. Product Illustrator, Icon Designer, Script Developer (Ai, Ps). Writing about bugs and tricks in Adobe Illustrator scripts