simple script to output selected object length?
I make a lot of stencils that become .25" laser cut plates & I need a script to quickly calculate the surface area of the final 3D plate.
The total surface area of the 3D plate is: (Front Surface Area) + (Back Surface Area) + (Perimeter*Material Thickness.)
The script below will give me the Front + Back, so I'm half way there.
I just need help getting the script to output the value normally found in the "Document Info" pallete, under "Objects --> Length"
Can anyone assist?
Thanks!
/* 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\n\
' + areaIn.toFixed(decimalPlaces) + ' in² \
' + areaIn.toFixed(decimalPlaces) * 2 + ' (in²)2 \n\
' + areaCm.toFixed(decimalPlaces) + ' cm² \
' + areaCm.toFixed(decimalPlaces) * 2 + ' (cm²)2 \n\
' + i + ' shapes');
}
