-
-
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'); | |
} |
Cool, thanks for updating this and helping out! I appreciate all the work you've done. Will you update the code when you iron out those bumps you were talking about?
Of course I will
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
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
Okay, i think i got it working now. Would you test this version. It now automatically check the scaleFactor
scale factor is automatically checked, dont need to check any setting or what so ever
version should show v0.1.7.1
https://github.com/schroef/Illustrator-Scripts/blob/master/GetShapeArea-dialog.jsx
Ill also check and see if i can get compound shapes to work better. It currently still has issues and doesnt return correct area.
@schroef wow, thanks for doing that so quickly! Will get this tested ASAP! :)
@schroef ericadyson is correct, you are a star! I have tested v0.1.7.1 using a simple 100x100cm square on a 600x600cm artboard and the old version gave an area of 100cm2 (100x too small) and v0.1.7.1 gave an area of 10,000cm2 which is correct! I need to do some further testing on more complicated designs, but for now it looks very promising. A HUGE THANK YOU :)
Make sure not use difficult compounds shape with negative shapes. I'm trying to figure out what's going wrong in those cases. It has issues when a group consists of multiple compundpathitems with negative (cutout) shapes and return faulty values
@schroef is it that it includes the negative/cutout area in the area calculation?
Those simple shapes work. I'll post a more complex shape when I'm at work. It when there is a group build of sub items which are compound shapes. Each of these have lots of cutouts. This is where it goes wrong. I must have made an error somehwere
Look here is an example of a more complex shape. The item in the middle is a group build of 4 compoundPathItem, noticed how the end result is wrong. It should be 250.0952 if my math is still correct
If i run on a single section, it does work
When i run a multi selection of compoundPathItems, it also seems to work correct. I did some tricks applying some filters and expanding it, to make sub items work. But something is going wrong
Its really depends on how the shape is build. Because if i group the the above version and then run it, it also returns that 250....
Check the sub items, i noticed that a shape can be build in different manner and looking the same. The way i am calculating compounds with negative shapes is by checking the polarity. Normally a cutout is negative. But it seems the most outer shape can also be negative and still show the same. Look at the images below. They look the same, but the outer shape has different polarity. Its kinda weird that its actually showing the shape correctly
@schroef are you only finding this with the design above or have you seen the same in other cases? I am not sure I can replicate the error.
@whitehorn799
Im still working on some other issues inbumpedninto. I noticed when a selection consists of multiple compoundpathitems, it would return the shape count as 1. Currently working on that. I believe the calculations are now fixed. As far as I can do that. I've noticed that still sometimes it returns a none round number even when the length and with are round numbers.. the pixel area is now as close as I can get it