-
-
Save nanoSpawn/8e8fca48d0fb85dd961e to your computer and use it in GitHub Desktop.
/* 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 */ | |
/* | |
Script grabbed from | |
https://gist.github.com/bryanbuchanan/11387501 | |
fixes negative areas "bug" (some areas are shown negative) | |
and shows result in square milimeters, given that's | |
the default unit used in document. | |
*/ | |
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 | |
// TODO, if no selection returned, objects.length is undefined | |
// and shows an error, not important, and still works fine, though | |
if (objects.length > 0) { | |
var totalArea = 0; | |
for (var i = 0; i < objects.length; i++) { | |
if (objects[i].area) { | |
// If negative, make it positive | |
var totalArea = totalArea + Math.abs(objects[i].area); | |
} | |
} | |
// 12.4451 is a multiplier that converts area returned to square milimeters. | |
// I guess Illustrator returns inches or feet, no idea really. | |
// Anyway, this value has been cherry picked from my own calculations. | |
totalArea = 12.4451 * totalArea / 10000; | |
// this part helps presenting a prettier alert | |
var area = "area"; | |
if (i != 1) { | |
area = "areas"; | |
} | |
// Conversions | |
/*var ppi = 72; | |
var areaInInches = Math.round((totalArea / ppi / ppi) * 100) / 100; | |
if (areaInInches < 0) var areaInInches = -areaInInches;*/ | |
// Display, I assume that 1 square milimeter = 1 square meter. | |
alert('Shape Area\n' + totalArea.toFixed(2) + ' square meters \n' + i + " " + area); | |
} | |
} |
I'll need to get back to this repo someday. It's an abandoned project I used to quickly fix stuff from the original code I forked. It's true that it has some mistakes, but since I no longer use Illustrator it's unlikely I'll go back to this. And also, I am not a devoted coder and I didn't study CS, I lack knowledge to generate proper code. I just suited a script to my needs while still keeping code public, because in all honestly, this does not belong to me.
Anyway, Shchroef, if you make a push I'll be glad to include any fixes from you so in the event people find this in the future they won't get broken code.
Hi @nanoSpawn i have 2 versions i was working on. I noticed they still have issues and wonder if it can actually be solved. Checking if items are compound shapes with cutouts is very tricky!
ive havent touched these in couple months, i added both versions i was working. I remember there was something odd going on in them. There could be some alerts in there as i was doing some testing
You can find them here
https://github.com/schroef/Illustrator-Scripts
PS this version is not based on your code, but its from the other fork from Bryan Buchanan and @alijaya contributor
I added a different UI and made it save items
If yours allows to work in units other than feet/inches and has better code, I could as well delete my gist to avoid confusion and spreading of bad code. Will try to check soon.
I made it so you can show 2 dimension at once and adjsut the decimals and to show total or sepatate shape areas
@P-D-Mac yes i am, i still need to drop them in a repo. Will try to do asap, ill tag you when i do. Otherwise do remind me, im currently doing a lot of PS scripting and some panel work.