I created a script that creates guides in the current document, the problem was if you don't check to see if they exist first, it'll keep making the same guide over and over again. Was trying to use switch cases, for logic on horizontal vs vertical, and may have gotten a bit too verbose, looping through multiple arrays. Is there a more straight forward way to accomplish checking the document for guides and creating if they don't exist? function psGuideCheck(guideToCheck, gDir) {
var aDG = app.activeDocument.guides;
var gResult = false;
if (aDG.length > 0) {
for (var i = 0; i < aDG.length; i++) {
if (guideToCheck == Math.round(aDG[i].coordinate.as('px')) && gDir == aDG[i].direction) {
var gResult = true;
break;
}
}
}
return gResult;
}
function psCreateGuides(cropLeft, cropTop, cropRight, cropBottom) {
var actDocG = app.activeDocument.guides;
var yLoc = [Math.round(cropTop), Math.round(cropBottom)];
var xLoc = [Math.round(cropLeft), Math.round(cropRight)];
var yDir = Direction.HORIZONTAL;
var xDir = Direction.VERTICAL;
//Loop Through Horizontal guides
for (var i = 0; i < yLoc.length; i++) {
var yPxGd = UnitValue(yLoc[i], "px").as('px'); //converts to the right value, and removes " px" from the end
if (psGuideCheck(yPxGd,yDir) == false) actDocG.add(yDir, UnitValue(yLoc[i], "px"));
}
//Loop Through Vertical Guides
for (var i = 0; i < xLoc.length; i++) {
var xPxGd = UnitValue(xLoc[i], "px").as('px'); //converts to the right value, and removes " px" from the end
if (psGuideCheck(xPxGd,xDir) == false) actDocG.add(xDir, UnitValue(xLoc[i], "px"));
}
}
psCreateGuides(-75, -75, 75, 75);
... View more