Copy link to clipboard
Copied
__________________
for(p=0; p<app.activeDocument.pages.length; p++){
var combineMe = new Array;
app.findObjectPreferences = null;
app.findObjectPreferences.appliedObjectStyles = "Style";
found_list = app.activeDocument.findObject(true);
for (a=0; a<found_list.length; a++)
{
if (found_list[a] instanceof TextFrame)
combineMe.push(found_list[a]);
}
combineMe.sort (function (a,b) { return (a.geometricBounds[0] < b.geometricBounds[0]) || (a.geometricBounds[0] == b.geometricBounds[0] && a.geometricBounds[1] < b.geometricBounds[1]) ? -1 : 1; } );
for (i=0; i<combineMe.length-1; i++)
{
if (combineMe[i].nextTextFrame == null)
{
nextFree = i+1;
while (nextFree < combineMe.length && combineMe[nextFree].previousTextFrame != null)
nextFree++;
combineMe[i].nextTextFrame = combineMe[nextFree];
}
}
}
When you're calling
found_list = app.activeDocument.findObject(true);
even though you think you're working by page, you're actually finding all matched objects throughout the document and adding them to the array. There's probably more efficient ways of going about this, but I would just search the whole document once, rather than iterating through pages. The following adds to the sort method a check to see if they are are on a previous page, then just relinks everything:
var sortFrames = func
...
Copy link to clipboard
Copied
When you're calling
found_list = app.activeDocument.findObject(true);
even though you think you're working by page, you're actually finding all matched objects throughout the document and adding them to the array. There's probably more efficient ways of going about this, but I would just search the whole document once, rather than iterating through pages. The following adds to the sort method a check to see if they are are on a previous page, then just relinks everything:
var sortFrames = function (arr) {
arr.sort(function (a, b) {
if (a.parentPage.documentOffset < b.parentPage.documentOffset) {
return -1;
}
else if (a.parentPage.documentOffset > b.parentPage.documentOffset) {
return 1;
}
else {
if (a.geometricBounds[0] < b.geometricBounds[0]) {
return -1;
}
else if (a.geometricBounds[0] > b.geometricBounds[0]) {
return 1;
}
else {
if (a.geometricBounds[1] < b.geometricBounds[1]) {
return -1;
}
else if (a.geometricBounds[1] > b.geometricBounds[1]) {
return 1;
}
return 0;
}
}
});
};
var combineMe = new Array;
app.findObjectPreferences = null;
app.findObjectPreferences.appliedObjectStyles = "Style";
found_list = app.activeDocument.findObject();
for (a=0; a<found_list.length; a++) {
if (found_list[a] instanceof TextFrame) {
combineMe.push(found_list[a]);
}
}
sortFrames(combineMe);
for (var c = 0; c < combineMe.length - 1; c++) {
try {
combineMe[c+1].previousTextFrame = null;
combineMe[c].nextTextFrame = combineMe[c + 1];
} catch(e) {}
}
Now with testing 🙂
Copy link to clipboard
Copied
Hi Brian!
Thank you very much! It seems to work perfectly. I've tested in LTR & RTL documents.👌🏼
Copy link to clipboard
Copied
Great. FYI, this might break if any text frames are on the pasteboard.
Copy link to clipboard
Copied
Hi Brian,
this will break if any text frames are found on the pasteboard.
In that case parentPage will return null instead of a page object.
Also note:
If a text frame is found on a master page, parentPage.documentOffset will return -1.
Regards,
Uwe Laubender
( ACP )