-
-
Save bryanbuchanan/11387501 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 */ | |
var decimalPlaces = 3; | |
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; | |
// Display | |
alert('Shape Area\ | |
' + areaIn.toFixed(decimalPlaces) + ' in² \ | |
' + areaCm.toFixed(decimalPlaces) + ' cm² \n\ | |
' + i + ' shapes'); | |
} |
For some reasons, it got negative area for some paths, so for multiple paths it substracted them. not added. Fixed with adding math.abs:
var totalArea = totalArea + Math.abs(objects[i].area);
But unfortunately, now compound shape calculation doesn't work correctly ¯_(ツ)_/¯
Love this! I think it would fit into a project I'm working on.
Does anyone think it would be possible to give the total area of every spot colour in a document? I am limited by having to select the shapes.
now compound shape
Yeah, this original version is great but is minimal. You can also have a look at my altered version. There is still a minor issue now, it has some issues sometimes with a combination of pathItems and compoundPathItems mixed together.
https://github.com/schroef/Illustrator-Scripts/blob/master/GetShapeArea-dialog.jsx
Im not sure adding this to the script will help. Its kinda of a specific workflow
Have a look at my version. It has been updated with more functionality
https://github.com/schroef/Illustrator-Scripts/blob/master/GetShapeArea-dialog.jsx
You can easily use magic wand to iterate over colors and than run the script each time
Thank you bro! Btw, can this one work on Adobe Photoshop 2024 too?
谢谢你,兄弟!顺便说一句,这个也可以在 Adob e Photoshop 2024 上运行吗?
Ah i tried and it failed...
@V-E-R-I-T-A-S
No its an Illustrator script. Photoshop doesnt have a prop like area. But they have the measurement tool there
You'd need to convert the image to a selection, convert the selection to a path, export the path to Illustrator, then run the script in Illustrator.
@V-E-R-I-T-A-S No its an Illustrator script. Photoshop doesnt have a prop like area. But they have the measurement tool there
It seems like PS cannot measure an irregular area...
You'd need to convert the image to a selection, convert the selection to a path, export the path to Illustrator, then run the script in Illustrator.
Thx! I am turning my work into illustrator
@whitehorn799
Of course I will