Help Adjusting Space based on Shape Height
Hello,
I currently have a script that will adjust the spacing between shapes based on the size of the shape.
If the shapes are smaller than 0.2" in height or larger than 0.5" in height, I want the shapes NOT to move, but an alert to come up instead, referencing the size is out of Production Standards.
Could anyone please take a look at what I have and help me?
Thank you!
// instructions: select path items
var space = .0235 * 72; // minimum space between paths (inches)
var doc = app.activeDocument;
var sel = doc.selection.height;
var maxHeight = 0;
// Capture Height
for (var i = 0; i < app.selection.length; i++) {
var _item = app.selection[i];
if (_item.height > maxHeight) {
var maxHeight = _item.height;
};
}
var shpHeight = (maxHeight / 72)*.9525;
function alignObj0(tabs,space) {
var esp;
// Max Height If Statement Specs
if (shpHeight <= 0.2){
var maxOverlap = 0
var nestOverlap = 0
alert("Size is Outside of Production Standards");
}if (shpHeight > 0.2 && shpHeight <= 0.25){
var maxOverlap = -2.54
var nestOverlap = -0.85
// alert("Small");
}if (shpHeight > 0.25 && shpHeight <= 0.35){
var maxOverlap = -4.74
var nestOverlap = -1.22
//alert("Medium");
}if (shpHeight > 0.35 && shpHeight <= 0.45){
var maxOverlap = -6.42
var nestOverlap = -1.82
//alert("Large");
}if (shpHeight > 0.45 && shpHeight <= 0.5){
var maxOverlap = -8.16
var nestOverlap = -2.47
//alert("X Large");
}if (shpHeight > 0.5){
var maxOverlap = 0
var nestOverlap = 0
alert("Size is Outside of Production Standards");
};
tabs.sort(function (a, b) {return a.left - b.left});
for (var i = 1; i < tabs.length; i++) {
// Really Tight Spacing
esp = tabs[i].left-tabs[i-1].left-tabs[i-1].width; //alert(esp);
if (esp < maxOverlap) {
for (var j = i; j < tabs.length; j++) {
tabs[j].left += (esp*(-1))+space;
}
// Natural Nested Spacing
} if (esp > maxOverlap && esp <= nestOverlap) {
for (var j = i; j < tabs.length; j++) {
tabs[j].left += 0
}
// Needs Spacing Situation 1
} if (esp > nestOverlap && esp <= 0) {
for (var j = i; j < tabs.length; j++) {
tabs[j].left += space-((esp/5)*4)
}
// Needs Spacing Situation 2
} if (esp > 0 && esp <= space) {
for (var j = i; j < tabs.length; j++) {
tabs[j].left += space-((esp/5)*4)
}
// Spacing is Good as is
} if (esp > space) {
for (var j = i; j < tabs.length; j++) {
tabs[j].left += (space * 0)
}
}
}
};
if (selection.length) {alignObj0(selection,space);};
Thank you!
