Copy link to clipboard
Copied
Having an issue with my script not finding all text frames in a document. I'm attaching an image of the layer configuration. There are three text frames in the document. One has text I don't want. One has text I want. And one is empty.
Here is the code in my script that is missing the frame I do want (red text in img below):
var doc = app.open(File(f));
var allTfs = doc.textFrames;
for (var i = 0; i < allTfs.length; i++) {
$.writeln(allTfs[i].contents); //writes the green found text from img
}
Here is some same code in a separate unitTest function. If I run this on an already open file, red text is found but not green text:
var unitTest = function() {
var allPageItems = app.activeDocument.textFrames;
for (var i = 0; i < allPageItems.length; i++) {
if (allPageItems[i].constructor.name == "TextFrame") {
$.writeln(allPageItems[i].contents);
}
}
}
unitTest();
I think it may have to do with how the text frames are grouped? Maybe? Or within the clip group? But how do I get them all? Thanks.
Hi @brianp311, I couldn't reproduce this using your code—it worked no matter how many groups or clipping groups I made.
Maybe you could try simplifying the structure step by step (eg. remove one level of grouping) until the script returns the contents you want? Might be something different about your file that I didn't match in my test. Curious!
- Mark
Hmm, here's a revised function where this happened:
The text frame being missed says "CUT#". Removing the frame the Clip Group solved it.
var unitTest = function() {
var f = File.openDialog();
var doc = app.open(f);
var count = 0;
var allTfs = doc.textFrames;
var cutRx = /^(\s+)?cut\s?#?(\s+)?$/gi;
for (var i = 0; i < allTfs.length; i++) {
$.writeln(allTfs[i].contents);
if (cutRx.test(allTfs[i].contents)) {
allTfs[i].contents = "xxxx";
...
Copy link to clipboard
Copied
Hi @brianp311, I couldn't reproduce this using your code—it worked no matter how many groups or clipping groups I made.
Maybe you could try simplifying the structure step by step (eg. remove one level of grouping) until the script returns the contents you want? Might be something different about your file that I didn't match in my test. Curious!
- Mark
Copy link to clipboard
Copied
Similar to @m1b, I get the expected result, which makes sense, since textFrames is an all-transcending collection.
Copy link to clipboard
Copied
Hmm, here's a revised function where this happened:
The text frame being missed says "CUT#". Removing the frame the Clip Group solved it.
var unitTest = function() {
var f = File.openDialog();
var doc = app.open(f);
var count = 0;
var allTfs = doc.textFrames;
var cutRx = /^(\s+)?cut\s?#?(\s+)?$/gi;
for (var i = 0; i < allTfs.length; i++) {
$.writeln(allTfs[i].contents);
if (cutRx.test(allTfs[i].contents)) {
allTfs[i].contents = "xxxx";
count++;
}
try {
allTfs[i].createOutline();
} catch(e) {
alert("Could not create text outlines: " + e);
}
}
}
Copy link to clipboard
Copied
@m1b helped me solve this. The full problem code had me creating text outlines, which was removing the text frame references. Iterating backward solved it.