A script to re-write caption numbers in Adobe Illustrator

The problem

You can use my MS Word figure numbering system to easily re-order, add, or remove figures from the document and have all the text's figure numbers adjust automatically. But what about the figure captions themselves? If you have 50 figures and want to remove #2, then you have to renumber the figure captions of figures 3 - 50 to now be 2 - 49! Ouch!

The solution

I've written a javascript that will run from within Adobe Illustrator, which will look for a figure number in the filename, and substitute it for the figure number in the caption within the file. The script has been tested on Illustrator CS3 for the Mac, but should, I believe, work on any platform and work in any version since CS1 (and possibly earlier).

Warning!

You should test this script first on copies of your files before you run it on the real ones. Or, you can just do it the safe way:

  1. duplicate your directory of figures
  2. run the script on the directory
  3. check the files to be sure it worked right
  4. delete the original directory

How to use the script

Setup

The script needs to know how to read your figure file names, and the figure captions. You can easily adjust the script by editing it in any text editor (e.g., Notepad or TextWrangler, but not MSWord or TextEdit). You need to tell the script exactly what text comes before the digits of your figure number and after, in both the file names and the text captions themselves.

The default version of the script expects "Fig " (note the space) to precede the digits in the filename, and "-" to succeed the digits (and then there can be any other text following that, so "Fig 03-Regional Map" is a valid name). The deafult settings expect "Figure " to preceded the digits in the text caption with in the Illustrator file, and "." to succeed the digits.

File names

Because the script gets the figure numbers from the file names, before you begin you should ensure that you have a single folder with only figure files, and that the figure numbers in the files are the correct ones, and that all the file names conform to the specification expected by the script.

For OSX, there is an easy way to do this: Get the free program NameMangler, and then change the file names to get them to sort correctly (see the sample files in the download for an example). All the files should start with "Fig " and then have some text (you can put anything in this part to make the files sort correctly) and then "-" and then something descriptive about the figure. Select all the files, and then drag them onto the droplet called "Renumber Figure Files". The files should renumber into the correct syntax and order, including the initial zeros. Note that if you have more than 99 figures, this droplet won't work correctly.

For Windows, you will have to work something out on your own to get the files named correctly. I'm sure there are similar programs, and you could also use the command line, if you know how.

One great feature: you can label your figures 001, 002, 003, ... if you wish, and the script will discard the initial zeros when making the captions. This is useful because most file systems will sort them wrongly (textually, not numerically) if you leave off the zeros, putting figure 2 between 19 and 20, and figure 3 between 29 and 30.

Running

Run Illustrator, and go to File > Scripts > Other Script. From the file chooser that appears, select the javascript file (see below to download it). It will then ask you to choose the folder of figures, and will start chugging away on them. It will run unattended, so you can go get a coffee.

Caveat

This script will not work right if you have separate files for the parts of figures. So if you have a file for figure 3a and another for figure 3b, this script will not work for you. If you have a single file that uses layers to make multiple figures, with different captions on each layer, this script will not work for you.

Downlaoding

Here is the script, together with some sample files that need to be re-numbered.


I hope this is helpful. If you have more questions, ask me.

-Dave