Skip to main content
Known Participant
September 19, 2022
Answered

Auto numbering

  • September 19, 2022
  • 4 replies
  • 3802 views

Hello everyone,
Here is my problem:
I have to name a lot of objects in my illus. plan in order to count them but I lost a lot of time by renaming each of them.

I would like to know if it's possible to auto number a text box in order to have somthing like this when I'm duplicating the circle n°1.

 

Thank you,
PM

 

Thank you

 

 

Correct answer m1b

Just a last thing, in the script you gave me I would like to add a static text in order to have "CH. 001"
when my text is "1".
Exemple if I duplicate a lot of "1" I will have "CH. 001", "CH. 002", "CH. 003", "CH. 004".

 

It would be so perfect if you could solve my problem !!

Thank you again


Yep have a try with this one:

/**
 * Increments the contents of first
 * selected text frame and sets contents
 * of subsequent selected text frames
 * according to counter.
 */
(function () {

    // prefix of each number
    var prefix = "CH. ";

    // the length of number
    var len = 3;

    var doc = app.activeDocument,
        items = app.selection;

    for (var i = items.length - 1, n; i >= 0; i--) {
        if (items[i].constructor.name == 'TextFrame') {
            if (n == undefined)
                n = Number(items[i].contents.replace(/\D/g,''));
            items[i].contents = prefix + ('000' + (++n)).slice(-len);
        }
    }

})();

4 replies

m1b
Community Expert
Community Expert
September 19, 2022

Hi @polotrobo, as others have said, the scripting API doesn't give access to duplicate page item event so it can't be automatic unless you create a plug-in, which is much more involved.

 

However, my solution to this type of problem is to

(a) put all the numbering markers on a layer of their own, eg mine is called "numbering",

(b) duplicate them in order, starting at 1

(c) run this script:

 

/**
 * Sets the contents of first text frame
 * of every group item on specified layer
 * to the value of a counter.
 */
(function () {

    var doc = app.activeDocument,
        numberingLayer = doc.layers.getByName('numbering'),
        items = numberingLayer.groupItems;

    for (var i = items.length - 1, n = 1; i >= 0; i--, n++)
        items[i].textFrames[0].contents = n;

})();

 

(d) to adjust the order afterwards, just move the markers up or down in the layer panel and run the script again.

That's how I would do it.

- Mark

 

polotroboAuthor
Known Participant
September 20, 2022

Hi @m1b your script is almost perfect !

1: Your script has to run with a group of text and ellipse, I would like to run it just with the text.

2: I would like to run the script from the active number of my textbox, exemple: I want to start the script from the number 312 in order to have the next numbers, 313, 314 etc..

Thank you all for your help I've learnt a lot from your tips!

m1b
Community Expert
Community Expert
September 20, 2022

No worries. Here's a script that does that:

/**
 * Increments the contents of first
 * selected text frame and sets contents
 * of subsequent selected text frames
 * according to counter.
 */
(function () {

    var doc = app.activeDocument,
        items = app.selection;

    for (var i = items.length - 1, n; i >= 0; i--) {
        if (items[i].constructor.name == 'TextFrame') {
            if (n == undefined)
                n = Number(items[i].contents);
            items[i].contents = ++n;
        }
    }

})();
femkeblanco
Legend
September 19, 2022

It depends on your workflow. Scripts are not dynamic. A script cannot change the contents at the moment you duplicate a text frame manually. I see two options.

 

First, the script incrementally adds 1 to the contents of selected text frames, the script being run immediately after doing the duplicating manually.

 

Second, the script duplicates a selected text frame, once or a specified number of times, adding 1 to the contents each time. You either position the duplicates manually or through the script (e.g. at the tail of the preceding text frame).

CarlosCanto
Community Expert
Community Expert
September 19, 2022

can you share a sample file? or at least show your layer structure?

Kurt Gold
Community Expert
Community Expert
September 19, 2022

Similar requests have already been there in this forum. Some of them are pretty promising.

 

One approach that I'd recommend is a script called "NumeratesPoints", provided by Sergey Osokin. Its main advantage is that it allows you to control the order of the numeration based on the order of anchor points on a path.

 

For example, you can draw ten circles, (preferably) create a new layer, take the Pen tool, draw a path with anchor points exactly placed on the centre of the circles (or elsewhere). Then, while this path is selected, run the "NumeratesPoints" script, choose the appropriate settings in the script dialog and finally delete the path and the marker points if you don't need them.

 

See here: NumeratesPoints

 

polotroboAuthor
Known Participant
September 19, 2022

Thank you Kurt for your response, unfortunately this is not what I expected..

I just want that the box I duplicate change automatically the number of the text box.
Exemple: I have written "1" in my text box -> I duplicate the textbox -> I now have "2" written in my new text box.

Thank you again

Participant
September 19, 2022

This might be possible using either scripting in Illustrator (so a .js) or using a third party app such as Alfred. The approach would be to use a hotkey to activate the script. The script would take the contents of the clipboard, see it as a numerical value, then iterate the value, replace the contents of the clipboard, then paste it back onto the board. I have not done this kind of thing myself, just saying that if I had this kind of workflow issue then this is how I would approach it.