![Fox8063795](https://vmapp.org/images/player/000default.jpg)
: Finding all TexFrame and TextPath objects in an InDesign document via scripting I'm looking for a fast way to extract all the TextFrame and TextPath objects in a document via scripting. I have
I'm looking for a fast way to extract all the TextFrame and TextPath objects in a document via scripting.
I have a working implementation that works also for inline elements but it's really slow since it traverses all the objects recursively.
On a file with ~2000 elements (of them only 700 are TextFrames), this script takes 132 seconds to execute, which is a bit too much for a 2-year old i7 MBP.
This is the current implementation:
#include "undercorejs.js"
var allItems = [];
function recursiveSearchForTextObjects(elements) {
for (var j = 0; j < elements.length; j++) {
var child = elements[j];
if(child instanceof TextFrame || child instanceof TextPath){
if(_.indexOf(allItems, child) < 0){ // No dupes
allItems.push(child);
}
}
if(typeof child.allPageItems != "undefined"){
recursiveSearchForTextObjects(child.allPageItems);
}
if(typeof child.textPaths != "undefined"){
recursiveSearchForTextObjects(child.textPaths);
}
if(typeof child.groups != "undefined"){
recursiveSearchForTextObjects(child.groups);
}
}
}
var doc = app.activeDocument;
recursiveSearchForTextObjects(doc.allPageItems);
Is there a better way of extracting all the TextFrame/TextPath objects including the inline elements?
More posts by @Fox8063795
1 Comments
Sorted by latest first Latest Oldest Best
Yes, you just need to loop over document's allPageItems property to access all page items, no matter if they are nested or not.
Then you can check if they are text frames or text paths and if so, collect them all in an Array.
// @target InDesign
var doc = app.activeDocument;
var allTextFrames = [];
for (var i = doc.allPageItems.length - 1; i >= 0; i--) {
var pi = doc.allPageItems[i];
if(pi instanceof TextFrame || pi instanceof TextPath) {
allTextFrames.push(pi);
};
}
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.