Calculate area and path-length in AI using Scripts

December 1, 2013

KateBaldwin

I have needed to calculate the area of a shape in order to determine the acreage of a perspective property plot, and to measure the length of a pen-tool-traced transgenic seedling root. Measuring area, perimeter, and length is not built into Adobe Illustrator, but there is an easy work around.

This technique should work for all recent (perhaps all) versions of Adobe Illustrator. [2020 update, still works!]

  • Step 1: Either download this file, or make one yourself.
    • To make it yourself, paste this text into a simple text file (like notepad) and save it with the file extension .jsx:

alert(
“Area (millimeters): ” + (Math.abs(app.activeDocument.selection[0].area/8.03521617).toFixed(4)) + ” mm” +
“\nLength (millimeters): ” + (app.activeDocument.selection[0].length/2.8346567).toFixed(4) + ” mm” +
“\n\nArea (inches): ” + (Math.abs(app.activeDocument.selection[0].area/5184).toFixed(4)) + ” in” +
“\nLength (inches): ” + (app.activeDocument.selection[0].length/72).toFixed(4) + ” in”
);

  • Step 2: Open your file in Illustrator and select the path or object that you want to measure.
  • Step 3: Click on “FILE” and scroll down to ‘scripts.’ Select “Other Script.” A file dialog window should open up. Find and select AreaLength.JS. A small window will pop up that states the area and length/perimeter in inches.

Some details & options

Do you plan to use it often?
Then you might want this script to appear on the quick menu within illustrator so that you don’t have to navigate through your files every time you use it.
Here is where I put it on my PC to successfully make it show up in the menu:
C:\Program Files\Adobe\Adobe Illustrator CC (64 Bit)\Presets\en_US\Scripts

Rounding

This script rounds the decimal points to 4. If you want more or less, you can open AreaLength.JS in notepad/text editor and change “toFixed(4)” to a different number.

Units

Would you like to measure your paths in other units instead?
Change the text in the file.

Centimeters

alert(
“Area (centimeters): ” + (Math.abs(app.activeDocument.selection[0].area/803.521617).toFixed(4)) + ” cm” +
“\nLength (centimeters): ” + (app.activeDocument.selection[0].length/28.346567).toFixed(4) + ” cm” +
);

You can change it other units too. The default would give you the units in px, and there are 72 px per inch. Thus, in the ‘inch’ unit script we take the length is divided by 72, and the area is divided by 5184, which is 72 squared. If you make a new script, I recommend testing it on a shape of known size. You can do this by selecting the rectangle tool, single clicking once on the canvas. A dialog will pop up. Type in “1 cm” for width and “1 cm” for height (for example).