is there anyway in InDesign using Javascript to search for any text frames in a document that overlaps? I've been looking through a document with all the properties of TextFrame and can't find anything that might tell whether there's any overlapping boxes or not.
I don't know Javascript but do know Ruby so i understand bits of it.
Asked
Active
Viewed 889 times
0

Rebs
- 43
- 7
2 Answers
2
Each Page object has got a read only attribute textFrames
with alle textFrames on the page.
Each textFrame has got a method visibleBounds
which will return an array in the form of [x1,y1,x2,y2]
, so you can get the geometric bounds of this text frame.
So you need to iterate over all the textFrames of the page, get the bounds of each textFrame and then you must check if any of them overlaps wich each other.

PatrickD
- 1,136
- 5
- 7
0
Here is a simple code to find text frames that overlap. It loops through all spreads in an active document and pauses to report an overlap. Check it out.
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 (b = 0 ; b < pg.textFrames.length; b ++) {
var r1 = pg.textFrames [b];
for (c = 0 ; c < pg.textFrames.length; c ++) {
var r2 = pg.textFrames [c];
var gb1 = r1.geometricBounds;
var gb2 = r2.geometricBounds;
if ((r1 != r2) &&
(gb1 [0] > gb2 [0] && gb1 [0] < gb2 [2] && gb1 [1] > gb2 [1] && gb1 [1] < gb2 [3]) ||
(gb1 [2] > gb2 [0] && gb1 [2] < gb2 [2] && gb1 [1] > gb2 [1] && gb1 [1] < gb2 [3]) ||
(gb1 [0] > gb2 [0] && gb1 [0] < gb2 [2] && gb1 [3] > gb2 [1] && gb1 [3] < gb2 [3]) ||
(gb1 [2] > gb2 [0] && gb1 [2] < gb2 [2] && gb1 [3] > gb2 [1] && gb1 [3] < gb2 [3])) {
r1.select ();
var cnf = confirm ("Text frames overlap. Continue searching?", true, "Overlapping text frames");
if (!cnf)
exit ();
}
}
}
}

Michael
- 75
- 9
-
Please make sure to test before posting: the first line of this script contains an error. The property is called [`rulerOrigin`](http://jongware.mit.edu/idcs5.5js_html/idcs5.5js/pc_ViewPreference.html#rulerOrigin), not `ruleOrigin`. – Jongware Mar 08 '16 at 20:39
-
Thanks. The subject is the the main code not the commented part. Did you try that before down-voting? – Michael Mar 12 '16 at 03:14
-
But does not work without (at least) this correction. You can't see it as it now has been deleted, but there was a complaint about that. – Jongware Mar 12 '16 at 10:03