Copy link to clipboard
Copied
Hi All,
I have a catalog with contact details and Photo in margin. There are 1000+ data in a file and the file count is 100+ (Government youth enrollment data). Where are there are few photo height which exceeds it content length, which leads to cut off the following photo. Is there any algorithm in java script to identify the collision objects? IF we check every object against every other object it might take more time.
Copy link to clipboard
Copied
Probably not bulletproof but here is an approach:
#targetengine "overlaps"
var w = w || getWindow();
w.show();
function getWindow() {
var objs;
var w = new Window("palette");
w.alignChildren = ["fill","top"];
w.preferredSize.width = 200;
var ls = w.add("ListBox");
ls.onChange = function() {
if (!ls.selection || !objs ) {
app.select ( NothingEnum.NOTHING );
return;
}
app.select( objs[ls.selection.text] );
}
ls.preferredSize.height = 300;
var b = w.add('button', undefined, 'Refresh' );
w.add('button',undefined,'Cancel');
w.onShow = b.onClick = function() {
ls.removeAll();
objs = getObjects();
if ( !objs || !objs.ids ) {
return;
}
var n = objs.ids.length, i = 0;
while ( i< n) {
ls.add('item', objs.ids );
i++;
}
}
return w;
}
function getObjects() {
var doc = app.properties.activeDocument,
fgp = app.findGrepPreferences.properties, found,
n = 0, prevItem, nextItem, currItem, overlaps = {}, currVB, prevVB, currChar, prevChar, ids = [];
if ( !doc ) return;
app.findGrepPreferences.properties = {
findWhat:"~a"
}
found = doc.findGrep();
n = found.length;
while ( n-- ) {
currChar = found
; currItem = currChar.pageItems[0];
prevChar = found[n-1];
if ( !prevChar ) continue;
prevItem = prevChar.pageItems[0];
if ( currChar.parentTextFrames.length
&& prevChar.parentTextFrames.length
&& prevChar.parentTextFrames[0].id == currChar.parentTextFrames[0].id ) {
currVB = currItem.visibleBounds;
prevVB = prevItem.visibleBounds;
$.writeln( "ici" );
if (
( currVB[0] > prevVB[0] && currVB[0] < prevVB[2] )
||
( currVB[1] > prevVB[1] && currVB[1] < prevVB[3] )
) {
overlaps[currItem.id] = currItem ;
ids.push( currItem.id );
}
}
}
overlaps.ids = ids;
return overlaps;
}