Skip to content

Instantly share code, notes, and snippets.

@y1ann15
Forked from bryanbuchanan/GetShapeArea.jsx
Last active February 2, 2016 11:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y1ann15/98bdc63bd012fd4b51f3 to your computer and use it in GitHub Desktop.
Save y1ann15/98bdc63bd012fd4b51f3 to your computer and use it in GitHub Desktop.
Script to find the area of shapes in Adobe Illustrator
/* 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 */
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 ppMm = 2.834645669291;
var areaInMm = Math.round((totalArea / ppMm / ppMm) * 100) / 100;
if (areaInMm < 0) var areaInMm = -areaInMm;
// Display
alert('Shape Area\n' + areaInMm + ' square millimeters \n' + i + ' shapes');
}
@y1ann15
Copy link
Author

y1ann15 commented Oct 9, 2015

Same function, results in millimeters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment