Skip to main content
Participant
Jul 9, 2024 7:50 PM UTC
Question

Need help with making 308 different-numbered text boxes.

So I need to make lists of 30 numbers on a page until it reaches 308. What is the best way to do this? I've tried a script but it's giving an error and was just wondering if there was a better way to do it or if anyone has a better script to use. Any help is appreciated! 

Thanks in advance!

This topic is closed to new replies. Start a new post to keep the conversation going.

6 replies

m1b
Community Expert
Community Expert
Jul 10, 2024 3:09 AM UTC

As @Robert38512781pn4f mentioned, they may be better ways to do this. But since I had a function already that does most of this, I will share this script, too.

- Mark

/**
 * @file Make Numbered Text Frames On Artboards.js
 * 
 * Makes numbered text frames on available artboards.
 * Adjust the constants START, END, ITEMS_PER_ARTBOARD,
 * GAP_PTS and TEXT_SIZE_PTS.
 *
 * @author m1b
 * @version 2024-07-10
 * @discussion https://community.adobe.com/t5/illustrator-discussions/need-help-with-making-308-different-numbered-text-boxes/m-p/14728931
 */
(function () {

    const START = 1,
        END = 308,
        ITEMS_PER_ARTBOARD = 30;

    const GAP_PTS = 60,
        TEXT_SIZE_PTS = 30;

    var doc = app.activeDocument,
        total = END - START,
        len = Math.ceil(total / ITEMS_PER_ARTBOARD);

    if (doc.artboards.length < len)
        return alert('Not enough artboards to fit ' + ITEMS_PER_ARTBOARD + ' numbers per artboard.\n(' + doc.artboards.length + ' available, ' + len + ' required).');

    for (var i = 0, ab, bounds, remainder = total + 1, counter, frame, frames; i < len; i++) {

        frames = [];
        counter = Math.min(ITEMS_PER_ARTBOARD, remainder);

        while (counter--) {
            frame = doc.textFrames.add();
            frame.contents = total - (--remainder) + START;
            frame.textRange.size = TEXT_SIZE_PTS;
            frames.push(frame);
        }

        ab = doc.artboards[i];
        bounds = ab.artboardRect;

        arrangeItems({
            items: frames,
            gap: GAP_PTS,
            maxWidth: bounds[2] - bounds[0],
            origin: [bounds[0], bounds[1]],
        });

        if (remainder < START)
            break;

    }

})();


/**
 * Positions page items in a simple L-R, T-B grid,
 * given `maxWidth`, with `gap` between each item.
 * The `lineHeight` variable is the largest height
 * in a given row.
 * @author m1b
 * @version 2023-11-01
 * @param {Object} options
 * @param {Array<Number>} options.origin - the origin [x,y] of the top-left of the grid.
 * @param {Array<PageItem>} options.items - the items to position.
 * @param {Number} [options.maxWidth] - the maximum width of the grid area, in points (default: no maximum).
 * @param {Number} [options.gap] - the gap between items (default: 0).
 */
arrangeItems = function arrangeItems(options) {

    options = options || {};

    var origin = options.origin,
        items = options.items,
        maxWidth = options.maxWidth || Infinity,
        gap = options.gap || 0;

    var x = 0,
        y = 0,
        lineHeight = 0;

    for (var i = 0; i < items.length; i++) {

        var item = items[i];

        if (x + item.width > maxWidth) {
            // move down
            x = 0;
            y -= (lineHeight || item.height) + gap;
            lineHeight = 0;
        }

        // position the item
        items[i].position = [origin[0] + x, origin[1] + y];

        // move right
        x += item.width + gap;

        if (item.height > lineHeight)
            lineHeight = item.height;

    }

};
Translate
RobOctopus
Inspiring
Jul 9, 2024 8:06 PM UTC

could you provide an image of what youre looking for?

is Indesign an option for you?

Translate
Participant
Jul 9, 2024 8:17 PM UTC

It is, yes. And the layout would look somewhat like this. Each page would have 30 numbers and I need the numbers to go until 308- however many pages that is.

The layout doesn't matter too much, placing them would be easy, I'm just mainly looking for a way to get 300 unique textboxes without typing them.

Translate
RobOctopus
Inspiring
Jul 9, 2024 8:30 PM UTC

a script could do this, but i think learning InDesign's Data Merge tool would be better.

you would create an excel sheet of whatever Data you want. in this case it's just the numbers 1-300+.

Then you create a file in indesign and design the text box to your liking then merge the data and it will replicate the data through the design. It would be a multi-record merge.

Translate