[JSX]Having trouble finding all TextFrame objects in clip group

Adobe Community Professional ,
Dec 06, 2021 Dec 06, 2021

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.

 missing-tf.png

TOPICS
Scripting

Views

85

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Adobe Community Professional , Dec 06, 2021 Dec 06, 2021
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

Likes

Translate

Translate
Adobe Community Professional , Dec 06, 2021 Dec 06, 2021
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"; ...

Likes

Translate

Translate
Adobe Community Professional ,
Dec 06, 2021 Dec 06, 2021

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 06, 2021 Dec 06, 2021

Copy link to clipboard

Copied

Similar to @m1b, I get the expected result, which makes sense, since textFrames is an all-transcending collection. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 06, 2021 Dec 06, 2021

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);
        }
    }
}

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 06, 2021 Dec 06, 2021

Copy link to clipboard

Copied

LATEST

@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. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines