-
-
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'); | |
} |
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
Hi @schroef, firstly I just want to say thank you for keeping the AI Area script up-to-date for the past few years, and thank you to @bryanbuchanan for creating the script in the first place.
I have been using it for a couple of years now and for the most part, it works flawlessly. I just have one issue, when using the script in files with a large-sized canvas, the areas provided always seem to be 100x too small. I think this is because the script is reading the scale as 1:10 instead of 1:1 which seems to be an issue in older versions of AI and PDFs (https://helpx.adobe.com/uk/illustrator/kb/large-sized-canvas-troubleshooting.html)
For now I just use a work-around of manually multiplying the area provided by 100, but it would be great if you could update the script at some point to work correctly with large-sized canvases.
Thank you!
Yeah, that's is probably true. I think illustrator uses an internal scaling factor for this "new" large scale document. This script is not build for that.
Perhaps I can do some research, see if this properties are exposed for scripting. If so, than that would be an easy fix
Okay got my answer within 1 minute. Its exposed, I'll check if I can update it.
I had been working also on parts where the script still fails. That's internal compound path items. Still haven't found a method to properly do those. Tried many variations doing all kinds of automated path operators, but it keeps failing.
I'll do some work and see if I can implement the scaleFactor
@schroef thank you so much for looking into this so quickly.
What is the issue with compound paths? I thought it was providing the area accurately and I have therefore been using it to do so for a couple of years?
Well it does, but there are so manu different ways art can be created using a mix of shapes and compound paths. The issue arise when such such are combined into one, but are build of many separate sub items. There are certain cases where it's not working properly
I need to check again which cases. I made some test for this months ago. But then laid aside as I couldn't figure it out and worked on other scripts.
Ps I was just thinking. If you run alert(app.activeDocument.scaleFactor) from a simple jsx file. It will return the scale factor. If you use this in the latest getShapeArez you could apply a scale. I have not tested it yet. But I think it should work
@draugmot
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