Skip to main content
dublove
Legend
August 10, 2025
Answered

When there is no selection, how can I obtain all paragraphs and table cells in the document?

  • August 10, 2025
  • 1 reply
  • 908 views

If no objects are selected, all text Frames in current document will be processed.

I have two targets:
    1. Text paragraphs outside the table.
    2. Cells inside the table.
How can I get them?

 

Like this:

obj.texts[0].appliedParagraphStyle)=parStn;
obj.texts[0].tables.everyItem().cells.everyItem().texts[0].appliedParagraphStyle = bodyParStn;

This is my code above.
It seems that it can only go up to this point: alert(“here”);
There is no response below that.

    var myDocument = app.documents.item(0);
    var myStory = myDocument.stories;
    for (var s = 0; s < myStory.length; s++) {
        alert("here");
      var what = "^.";
        var res = getGrepSearch(what, app.activeDocument);
        for (var f = 0; f <res.length; f++) {
            var obj = app.selection[f];
...
}
}

 

Correct answer rob day

Hi Rob Day.
It seems that one scenario has been overlooked.

When no object is selected, how can we indicate that we want to retrieve images outside of the text box?

 


You can get all of the document’s graphics—this is an array not a collection:

 

var g = app.activeDocument.allGraphics
alert("An array of " + g.length + " graphics")

 

1 reply

rob day
Community Expert
Community Expert
August 10, 2025

Text paragraphs outside the table.

Cells inside the table.

 

var p = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements()
var c = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements()
alert("An array of " + c.length + " cells in this document")
alert("An array of " + p.length + " paragraphs in this document not included in tables")

 

 

 

dublove
dubloveAuthor
Legend
August 11, 2025

It's better to use variables instead of this method, otherwise it will be too long.
I was thinking about your function yesterday. I now have five scenarios, each with independent code, which is a bit long.