Site logo

Leavers hoodie script

Version 1.1

This custom script for InDesign was developed at a company’s request that prints hoodies for school leavers. Manually, they just paste the list of names into the number box and then adjust the text manually moving things around, adjusting font size, line spacing, kerning, and adding in spaces or line breaks until it looks ok, but it is quite difficult and time-consuming, and annoying!
The requirements are just to fit the children’s names in the outline of the “23” (for this year) and look neat and correct. All names need to be the same size as each other (no names bigger than others). Initial/surname would need to not be split from the first name by a line break. The shape should be filled with 1 or 2 times the name of each child (1 or 2 times depending on if we need to fill up more space when there aren’t many children, for instance).
The text frame is converted from text with the ‘create outlines’ command and adjusted manually. Now they want “23”, “24”, but in the future, they might need any word, like “Ski Trip” or “PE”.
My customers have looked on InDesign forums and other design forums and googled everything but they couldn’t find any software that will do this automatically for them with good results, or a way to easily do this in InDesign.
They could find wordcloud type software but often that makes lots of repetition and also makes some words bigger than others, which they don’t want as they don’t want one child to appear more ‘important’ than others, they all need to be the same size.

To speed up the process, I split it into two steps (scripts): the first script prepares the template creating text boxes, and the second fills in the boxes with names.
Probably, someday I will combine both scripts into one making, say, a dialog box with two tabs.

Step 1 — Prepare template

Watch here a short video of how it works.

The user selects a shape — a text frame created manually, in this case with the create outlines command — and runs the Prepare template script.

The script fills the shape with temporary placeholder text which contains only ‘I’ (Unicode: 0x49) characters repeated many times. It is used only for measuring lines’ widths. The narrowest character allows for the precisest measurements. The overset text is removed. Then the script loops through each line making text boxes for every line. Note that a line can be split, in this case, two or more separate boxes will be created for each part (text range). To measure the precise size and position of a box, the script temporarily creates an outline from the line and adds some space using the parameters defined in the variables at the top. These parameters can be changed by the user:

In a future version, I’m planning to make a dialog box for these settings.
Finally, the script creates text boxes on the Boxes layer like so:

Step 2 — Fill in boxes

Here's a video of how it works.

The script fills in text boxes created in step one on the current page.
The user runs the script and selects a text file (txt, rtf, docx, doc) with names.

At the moment, such a file can be in three variants:

Each name should be in a separate paragraph. The script places the file in a temporary text frame whose label is temp. If it doesn’t exist, it will be created automatically to the right of the first page. If a name has (regular) spaces, they are replaced with nonbreaking spaces. From this text, the script creates a list of names sorted by width.

Then it loops through every box trying to fill in names — as many as possible — into available space starting from the longest names. If a box gets overflown, the script tries to fix it, increasing the width (by the increment set in the increment variable) up to the limit set in the increaseLimit variable. Also, an extra space is added (the extraSpaceWidth variable). Probably, in the future, I add these parameters to the dialog box so the user could easily change them.

If all the names were used but empty boxes remain, the script begins another cycle until no empty boxes are left.

At the top, there’s the debug variable. If you set it to true, the script applies a different color to every cycle making them more visually perceptible, and creates a detailed log file on the desktop — the log variable should be set to true as well — that gives the idea of how it works.

If the script fails to fill in all boxes, for example, in case the boxes are too small for the names, it reverts the document and gives a warning.
In the debug mode, it also selects and displays the box on which the script stumbled.

To solve this issue you can experiment with paragraph style options. For example, I made the text narrower by setting the horizontal scale to 78% for the Names style used in boxes.

After this modification, the script successfully processed the full names.txt file.

Making a shape

Before using the script, you have to manually make a shape: a text frame of any form with one or more columns. In my test file (see the link at the bottom), I prepared templates for two years: 23 and 24. Originally it was a text converted to outlines. I added 2 pt inset and added one more column. Then moved the left edge of the right number to hide the gutter between the columns.

The file has a few styles that define formatting. Paragraph style Names formats placed names. In my opinion, lines should be aligned horizontally and vertical distances in the shape should be made multiple of a number of lines. For this reason, I set the baseline grid > increment every to 22 pt and the align to grid > all lines in the paragraph style. The verticalShift variable at the top of Prepare template script is set to -3.115 (the value was found experimentally) which moves boxes upwards a little making the text align the baseline grid. (Otherwise, it gets overset in small boxes). To make a proper shape, I run both scripts a few times, making adjustments to the shape here and there until I got the desired result.

Ideas for further improvement:

Finally, I want to mention that this is the very first version so, please, be lenient with me.

Click here to download the current versions of the scripts and test files you see in the screenshots and video above.


Related pages:

Here is my first attempt: Algorithm for fitting text into an irregular shape.
Here is my post on the Adobe InDesign forum.