Hi @lux65, here's some code that might help you with your project. It will thread any text frame that has the script label "NUMBERS". If you prefer using the name you can change that—either is fine. Text frames will be sorted by page order, then Y coordinate, then X coordinate.
- Mark

/**
* Thread text frames labelled "NUMBERS"
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/threading-all-textframe-in-document-skips-second-frame-in-page/m-p/13842736
*/
var targetScriptLabel = "NUMBERS";
function main() {
var doc = app.activeDocument,
allTextFrames = doc.textFrames,
targetFrames = [];
// we only want the text frames
// with target script label
for (var i = 0; i < allTextFrames.length; i++)
if (allTextFrames[i].label == targetScriptLabel)
targetFrames.push(allTextFrames[i]);
//sort in page order
targetFrames.sort(sortFrames);
// now we thread the frames, by only if
// they aren't already threaded properly
for (var i = 0; i < targetFrames.length - 1; i++)
if (targetFrames[i].nextTextFrame != targetFrames[i + 1])
targetFrames[i].nextTextFrame = targetFrames[i + 1];
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Thread "' + targetScriptLabel + '" Frames');
/**
* Sorts text frames based on page, then left position, then top position.
* @param {TextFrame} a - the TextFrame to sort.
* @param {TextFrame} b - the TextFrame to sort.
*/
function sortFrames(a, b) {
// by page number
if (a.parentPage.documentOffset < b.parentPage.documentOffset) return -1;
else if (a.parentPage.documentOffset > b.parentPage.documentOffset) return 1;
// by top-bottom
else if (round(a.geometricBounds[0]) < round(b.geometricBounds[0])) return -1;
else if (round(a.geometricBounds[0]) > round(b.geometricBounds[0])) return 1;
// by left-right
else if (round(a.geometricBounds[1]) < round(b.geometricBounds[1])) return -1;
else if (round(a.geometricBounds[1]) > round(b.geometricBounds[1])) return 1;
// same
else return 0;
function round(a) { return (Math.round(a * 1000) / 1000) };
};
Edit 2023-06-07: added sorting function so the layer order doesn't matter.
Edit 2023-06-17: changed sorting order to prefer left-right.
Edit 2023-06-18: changed sorting order to prefer top-bottom.
Edit 2023-06-18: improved sorting so that tiny Extendscript rounding errors are ignored.