That answer brought a script to find overlapping text boxes. And now I tried to adjust the script to find text boxes that cross the page margin, but the script does not work properly, and it alerts all the text boxes on the right-hand page of the double page as those that go through the page's margin, and I can't figure out the reason and how to define it correctly The code.
Maybe the problem is with how I set the array pageMargins
that includes my margin location?
The following is my code:
// find all out of margins textFrames
app.activeDocument.viewPreferences.rulerOrigin= RulerOrigin.SPREAD_ORIGIN;
//If you are going to work with pages, not spreads, change the line above to PAGE_ORIGIN;
for (a = 0; a < app.activeDocument.spreads.length; a ++) {
var pg = app.activeDocument.spreads [a];
for (e = 0 ; e < pg.pages.length; e ++) {
var singlePage = pg.pages[e];
for (b = 0 ; b < singlePage.textFrames.length; b ++) {
var r1 = pg.textFrames [b];
var gb1 = r1.geometricBounds;
var pageMargins = [singlePage.bounds [0] + singlePage.marginPreferences.top,
singlePage.bounds [1] + singlePage.marginPreferences.left,
singlePage.bounds [2] - singlePage.marginPreferences.bottom,
singlePage.bounds [3] - singlePage.marginPreferences.right
];
// check if it's overlapping page margins
if(!(gb1 [0] > pageMargins [0] && gb1 [1] > pageMargins [1] && gb1 [2] < pageMargins [2] && gb1 [3] < pageMargins [3]))
{
r1.select ();
alert("frame geometric bounds: " + gb1 + "\npage Margins: " + pageMargins + "\nnumber in spread: " + e + "\nsingle page bounds: " + singlePage.bounds + "\n")
var cnf = confirm ("Text frames overlap. Continue searching?", true, "Overlapping text frames");
if (!cnf)
exit ();
}
}
}
}