Quantcast

Finding areas and lengths in Illustrator

Posted by K8Baldwin K8Baldwin  
Report Content as Inappropriate
  Options

How to calculate the area of an object and length of a path in Adobe Illustrator using Scripts.

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 Illustrator, but there is an easy work around.

This technique should work for all recent (perhaps all) versions of Adobe Illustrator. Telegraphics makes a nice plug-in for finding area and lengthlength in Illustrator, but it doesn’t work for the lastest versions: Adobe Illustrator CS6 nor Adobe Illustrator CC. The technique I will describe here is just as easy to use, and more universal.

12 Comments

classic Classic list List threaded Threaded
cosmetik cosmetik
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

Hi!, Thanks for the tutorial!
Do you have any idea on how to modify the script to work while selecting several objects?
Randi Randi
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

In reply to this post by K8Baldwin
Perfect!
Thanks!
Angela Kane Angela Kane
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

In reply to this post by K8Baldwin
Thank you very much.  This works extremely well!
Cathy Cathy
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

In reply to this post by K8Baldwin
I tried using this and I am getting NaN, instead of a number. It works if i create a simple box, but not on a more complicated shape. Does the path or object need to be set up a specific way?
Thanks!
ryan ryan
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

In reply to this post by K8Baldwin
I run in the same problem with a complicated shape - result NaN, when I use the script.
What is the fix?
lvl99 lvl99
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

In reply to this post by K8Baldwin
I've adapted the code to calculate the total area of all selected objects (as per object's area):

```
var totalArea = 0;
var totalObjects = app.activeDocument.selection.length;
var output = "";

for( var i=0; i<app.activeDocument.selection.length; i++ ) {
  totalArea += parseFloat(Math.abs(app.activeDocument.selection[i].area/8.03521617).toFixed(3));
  output += "Object "+(i+1)+" Area: " + (Math.abs(app.activeDocument.selection[i].area/8.03521617).toFixed(3)) + "\nLength: " + (app.activeDocument.selection[i].length/2.8346567).toFixed(3)+"\n\n";
}

alert("Area of "+totalObjects+" objects (mm): "+totalArea+"\n"+output);
```
mak mak
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

In reply to this post by K8Baldwin
@ lvl99

ABSOLUTELY THE BEST ADVISE !!!!!

just copy and paste into notepad the text between the two lines of  ```
and save the file as:

AreaLength.JS

for example in desktop.

Go to desktop, locate the file, right click and at he bottom choose properties.
Under the "General" tab look for  "Opens with:" and press button to the right which says '"Change "
Under "Recommended Programs" or "Other Programs" look  for and click on "Adobe Illustrator" then click main window "OK" button.
If you can't see adobe illustrator option you have to click "Browse" to locate the illustrator.exe file under the program files (86 if 32 bit)

now every time you select a shape in illustrator and then go to desktop and double click "AreaLength.JS"  file, illustrator reappears and dialog window gives you area information for the selected object.

Alternatively after saving the file "AreaLength.JS " to desktop, go to illustrator and open the file containing the shape which surface you wan't to measure. Click and select the shape to measure then press Ctrl+F12 to open explorer. Navigate to desktop and find and select the file "AreaLength.JS" press "OK". Dialog window comes up with correct measurement.

mak mak
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

In reply to this post by K8Baldwin
... and even further ...

if you change the name from "AreaLength.JS" to a "AreaLength.jsx", then  you can drag this file into your adobe folder so it always appears as an option under File>Scripts directly without looking for other scripts.

You want to move and copy this file into (32 bit)

C:\Program Files (x86)\Adobe\Adobe Illustrator CS6\Presets\en_US\Scripts

and / or (64bit)

C:\Program Files\Adobe\Adobe Illustrator CS6 (64 Bit)\Presets\en_US\Scripts

depending on software version

This way it becomes part of the illustrators menu under File>Scripts

... have fun ...
ma4ine ma4ine
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

This post was updated on .
In reply to this post by lvl99
Big thanks! Some metrics variants of your great script for 1:10 scale:



- CM VERSION -

var totalArea = 0;
var totalObjects = app.activeDocument.selection.length;
var output = "";

for( var i=0; i<app.activeDocument.selection.length; i++ ) {
  totalArea += parseFloat(Math.abs(app.activeDocument.selection[i].area/803.521617).toFixed(3));
  output += "Object "+(i+1)+" Area: " + (Math.abs(app.activeDocument.selection[i].area/803.521617).toFixed(3)) + "\nLength: " + (app.activeDocument.selection[i].length/283.46567).toFixed(3)+"\n\n";
}

alert("Area of "+totalObjects+" objects (сm): "+totalArea+"\n"+output);



- M VERSION -

var totalArea = 0;
var totalObjects = app.activeDocument.selection.length;
var output = "";

for( var i=0; i<app.activeDocument.selection.length; i++ ) {
  totalArea += parseFloat(Math.abs(app.activeDocument.selection[i].area/80352.1617).toFixed(3));
  output += "Object "+(i+1)+" Area: " + (Math.abs(app.activeDocument.selection[i].area/80352.1617).toFixed(3)) + "\nLength: " + (app.activeDocument.selection[i].length/28346.567).toFixed(3)+"\n\n";
}

alert("Area of "+totalObjects+" objects (m): "+totalArea+"\n"+output);
Pedro Sanchez Pedro Sanchez
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

In reply to this post by ryan
I was having the same problem with the NaN error (even with lvl99's tweak), but realised that it was only happening on compounded shapes. To solve the problem uncompound the shape that you are trying to calculate the area/perimeter of (select the shape and press shift+ctrl+Alt+8) and then select all of the individual components and rerun lvl99's script. This will then give you the areas and perimeters of all of the individual components, which is very useful when trying to calculate cutting time for a job (for example). You should find that the error goes away, or at least it did for me.

Thanks a lot for your help!
EliEverhart EliEverhart
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

In reply to this post by ma4ine
Hello,
I found your script very helpful.  I miss the functionality of the Telegraphics Plugin that worked many years ago.


Would you or someone else mind guiding me on how to convert to US/Standard units instead of Metric?

Additional request:  Is there anyway to write this script so that it can accommodate compound paths?
*This is something I would be willing to pay for if reasonable.  [Paypal]

Thanks in advance for any help received!
-Eli

K8Baldwin K8Baldwin
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding areas and lengths in Illustrator

In reply to this post by K8Baldwin
Hello Eli,

I think this more complicated script written by Bryan Buchanan might do what you want.
I changed it to display in both inches and millimeters, and to show 3 decimal points.
Here it is downloadable, and below I pasted the text:

/* Save this file with a jsx extension and place in your
Illustrator/Presets/en_US/Scripts folder. You can then
access it from the File > Scripts menu
Written by Bryan Buchanan
Source of this script: https://gist.github.com/bryanbuchanan/11387501#file-getshapearea-jsx-L1*/

if (app.documents.length > 0) {
        if (app.activeDocument.selection.length < 1) {
                alert('Select a path first');
        } else if (app.activeDocument.selection[0].area) {
                // Individual Items
                var objects =  app.activeDocument.selection;
        } else if (app.activeDocument.selection[0].pathItems) {
                // Group/Compound Shape
                var objects = app.activeDocument.selection[0].pathItems;
        } else {
                alert('Please select a path or group.');
        }
                // Collect info
        var totalArea = 0;
        for (var i=0; i<objects.length; i++) {
                if (objects[i].area) {
                        var totalArea = totalArea + objects[i].area;
                }}
    // Conversions    
        var ppi = 72;
        var areaInInches = Math.round((totalArea / ppi / ppi) * 100) / 100;
        if (areaInInches < 0) var areaInInches = -areaInInches;
        var areaInMm = areaInInches * 645.16;
                // Display
        alert('Shape Area\n' + areaInInches.toFixed(3) + ' square inches \n'  + areaInMm.toFixed(3) + ' square millimeters \n' + i + ' shapes');
}

Loading...