Skip to main content
Known Participant
February 2, 2016
Question

how to build one array of TextFrames from indd spread consist of TextFrames being grouped and not being grouped ?

  • February 2, 2016
  • 2 replies
  • 514 views

1. I need to have all the textFrames of indd document collected in one array. some of them are members of group, some not. I don't know how to do it in simple way, not to concat two arrays of dropped and not grouped frames?

2. textFrames have contents and are marked as XMLmarkupTags.

How to build condition which will search for specified content eg. "a" only in textFrames marked by specified markupTag eg. "A" ?


regards

marcin

This topic has been closed for replies.

2 replies

ypsillonAuthor
Known Participant
February 5, 2016

many thanks for answers Laubender and Vamitul. It helped me a lot :-)

Community Expert
February 2, 2016

Hi marcin,

for getting all text frames into one array you can use the textContainers property of the story object.

For example:

// Array that will hold the text frames:

var textFramesArray = [];

// The active document:

var doc = app.documents[0];

// All stories in the document:

var stories = doc.stories.everyItem().getElements();

// Loop through all the stories:

for(var n=0;n<stories.length;n++)

{

    // The textContainers could be text frames or text paths

    var textContainersArray = stories.textContainers;

    // Loop through the text containers:

    for(var c=0;c<textContainersArray.length;c++)

    {

        // Single out the text frames:

        if(textContainersArray.constructor.name == "TextFrame")

        {

            // Feed the array:

            textFramesArray[textFramesArray.length++] = textContainersArray;

        };

    };

};

If you also would like to add text paths to that array, you don't need the if statement; just feed the array how is shown in line 22.

For question #2 I have no answer…

Uwe

Vamitul
Legend
February 3, 2016

Laubender‌ Your code won't work if there are textframes in the document that have no content.

Simplest way is to use the allPageItems array and just pick the texframes from there;

var doc=app.activeDocument;

var tf=[];

for (var i=0; i<doc.allPageItems.length; i++){

if(doc.allPageItems.constructor.name=='TextFrame') {

   tf.push(doc.allPageItems);

}

}

Community Expert
February 3, 2016

Hm. I tested ok with empty text frames…

Uwe