-
-
Save cakirefekan/d5a4b6d13fc4d76f7dc1dac773d0aa04 to your computer and use it in GitHub Desktop.
Script to find the area of shapes in Adobe Illustrator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 */ | |
var decimalPlaces = 3; | |
var scale = prompt("1/", " ", "Enter Scale"); | |
if (app.documents.length > 0) { | |
if (app.activeDocument.selection.length < 1) { | |
alert("Select a path"); | |
} 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 areaIn = totalArea / ppi / ppi; | |
if (areaIn < 0) var areaIn = -areaIn; | |
var areaCm = areaIn * 6.4516; | |
var areaM = areaCm / 10000; | |
var scaledAreaCm = areaCm * scale * scale; | |
var scaledAreaM = areaM * scale * scale; | |
// Display | |
alert( | |
"Shape Area\ | |
" + | |
areaCm.toFixed(decimalPlaces) + | |
" cm² in 1/" + | |
scale + | |
"\ | |
" + | |
areaM.toFixed(decimalPlaces * 2) + | |
" m² in 1/" + | |
scale + | |
" \n\ | |
" + | |
scaledAreaCm.toFixed(decimalPlaces) + | |
" cm² in 1/1 \ | |
" + | |
scaledAreaM.toFixed(decimalPlaces) + | |
" m² in 1/1 \n\ | |
" + | |
i + | |
" shapes" | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment