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?