Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Guide ,
Aug 10, 2025 Aug 10, 2025

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];
...
}
}

 

TOPICS
How to , Scripting
644
Translate
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 5 Correct answers

Community Expert , Aug 10, 2025 Aug 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")

 

 

 

Screen Shot 54.pngScreen Shot 55.png

Translate
Community Expert , Aug 12, 2025 Aug 12, 2025

If I select a framework

 

So there is a selection? If so:

 

 

//make sure there is a selection
try {
    //the parent of a text frame’s text is a story
    var s = app.activeDocument.selection[0].texts[0].parent

    //all of the paragraphs in the selection
    var p = s.paragraphs.everyItem().getElements()
    //all of the cells in the text’s tables
    var c = s.tables.everyItem().cells.everyItem().getElements()
    alert("An array of " + c.length + " cells in this selection")
    alert("An a
...
Translate
Community Expert , Aug 13, 2025 Aug 13, 2025

Watch out for the difference between an Array and a Collection, they are similar but not the same—allGraphics returns an Array, while pageItems returns a Collection:

 

//allGraphis is an array not a collection
var g = app.activeDocument.stories.everyItem().allGraphics
//pageItems is a collection not an array and can be converted 
//to an array by adding everyItem().getElements()
var pi = app.activeDocument.stories.everyItem().pageItems.everyItem().getElements()

alert("Story 1 has " + g[0].leng
...
Translate
Community Expert , Aug 13, 2025 Aug 13, 2025

Can I look down to the child?

No—there’s no child property

You can get the object’s properties—this gets the first pageItem’s properties as a text list

 

var p=app.activeDocument.pageItems[0].properties.toSource(); 
alert("Properties:\r" + p)  

 

 

 

Translate
Community Expert , Aug 18, 2025 Aug 18, 2025

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")

 

Screen Shot 9.png

Translate
Community Expert ,
Aug 10, 2025 Aug 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")

 

 

 

Screen Shot 54.pngScreen Shot 55.png

Translate
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
Guide ,
Aug 10, 2025 Aug 10, 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.

Translate
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
Guide ,
Aug 10, 2025 Aug 10, 2025

I suddenly realized that I chose table and text, and constructor.name is also “Text”.
So how can I distinguish it from pure text?

ac.pngad.png

Translate
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
Community Expert ,
Aug 11, 2025 Aug 11, 2025

If no objects are selected 


In your first post you wrote there is no selection

Translate
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
Guide ,
Aug 11, 2025 Aug 11, 2025

I now use this method to distinguish between them:

f ((
    (app.selection[0].constructor.name == “TextColumn”)
    || (app.selection[0].constructor.name == “Text”)
    || (app.selection[0].constructor.name == “TeStyleRangle”))
    && ((app.selection[0].texts[0].tables.length > 0)
        || (app.selection[0].texts[0].Rectangles.length > 0)))
 {
    selTextTable();
}

 

Translate
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
Community Expert ,
Aug 12, 2025 Aug 12, 2025

@dublove said: "… So how can I distinguish it from pure text?"

Hi, in this context a table is "stored" as a special character.

From the context of a found table you can get that special character through its first insertion point, that is expressed by the property storyOffset of a table.

 

Thus the special character is myTable.parent.characters[ myTable.storyOffset.index ] .

 

// Table selected:
var myTable = app.selection[0];

// Select the special character that contains the selected table from above:
app.select( myTable.parent.characters[ myTable.storyOffset.index ]);

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Translate
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
Guide ,
Aug 12, 2025 Aug 12, 2025

Hi Laubender.

I don't think you understand what I mean. This is too complicated.

maybe, is it  like this?

c = app.activeDocument.stories[0].tables.everyItem().cells
Translate
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
Community Expert ,
Aug 12, 2025 Aug 12, 2025

This is too complicated.

 

What is making it complicated— in your post title you write there is no selection, but in your last post you have 3 text frames selected. If there is a selection you have to test what it is, which does make it much more complicated.

 

Translate
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
Guide ,
Aug 12, 2025 Aug 12, 2025

Hi Rob Day.
I tested it.
This works:

var c = app.activeDocument.stories[0].tables.everyItem().cells;
Sorry, I may not have explained it clearly.
What I mean is:
When I select a text box, my goal is to select the entire article (the entire stor

Translate
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
Guide ,
Aug 13, 2025 Aug 13, 2025

When no object is selected:

    var t = app.activeDocument.stories.everyItem().tables;
    var g = app.activeDocument.stories.everyItem().allGraphics;
    alert(t.length);
    alert(g.length);

 

dublove_0-1755075384520.jpeg

The result of alert(t.length) is correct.
It outputs 3, which is indeed the number of tables.

 

However, alert(g.length) seems to be incorrect, as there are three graphs.
The output is 2.

Translate
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
Community Expert ,
Aug 13, 2025 Aug 13, 2025

Watch out for the difference between an Array and a Collection, they are similar but not the same—allGraphics returns an Array, while pageItems returns a Collection:

 

//allGraphis is an array not a collection
var g = app.activeDocument.stories.everyItem().allGraphics
//pageItems is a collection not an array and can be converted 
//to an array by adding everyItem().getElements()
var pi = app.activeDocument.stories.everyItem().pageItems.everyItem().getElements()

alert("Story 1 has " + g[0].length + " graphics")
alert("All document stories have " + pi.length + " page items")

 

Screen Shot 19.png

 

 

 

Screen Shot 20.png

Translate
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
Guide ,
Aug 12, 2025 Aug 12, 2025

Hi rob day.

If I select a framework, what are all the frameworks linked to it called?
Is it called a story?
How to represent paragraphs (p) in a story and cells (c) in a table?

858.png

 

Translate
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
Community Expert ,
Aug 12, 2025 Aug 12, 2025

If I select a framework

 

So there is a selection? If so:

 

 

//make sure there is a selection
try {
    //the parent of a text frame’s text is a story
    var s = app.activeDocument.selection[0].texts[0].parent

    //all of the paragraphs in the selection
    var p = s.paragraphs.everyItem().getElements()
    //all of the cells in the text’s tables
    var c = s.tables.everyItem().cells.everyItem().getElements()
    alert("An array of " + c.length + " cells in this selection")
    alert("An array of " + p.length + " paragraphs in this selection not included in tables")
}catch(e) {
    alert(e)
}  

 

 

Translate
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
Guide ,
Aug 13, 2025 Aug 13, 2025

When selecting a frame, point to the entire article.
I still used yours, as parent can accurately lock the relationship.
Mine sometimes misleads to other unrelated affected areas.

Translate
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
Community Expert ,
Aug 13, 2025 Aug 13, 2025

Also, you can get the pageItem’s graphics, which is a Collection:

 

var g = app.activeDocument.stories.everyItem().pageItems.everyItem().graphics.everyItem().getElements()
alert(g.length)

 

Screen Shot 21.png

Translate
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
Guide ,
Aug 13, 2025 Aug 13, 2025

Hi rob day.
Thank you very much.

 

I can use .parent to look up the parent.
Can I look down to the child? 

See what relationships are included in a certain layer.

Translate
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
Community Expert ,
Aug 13, 2025 Aug 13, 2025

Can I look down to the child?

No—there’s no child property

You can get the object’s properties—this gets the first pageItem’s properties as a text list

 

var p=app.activeDocument.pageItems[0].properties.toSource(); 
alert("Properties:\r" + p)  

 

 

 

Translate
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
Guide ,
Aug 18, 2025 Aug 18, 2025

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?

dublove_0-1755518337966.jpeg

 

Translate
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
Community Expert ,
Aug 18, 2025 Aug 18, 2025
LATEST

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")

 

Screen Shot 9.png

Translate
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
Community Expert ,
Aug 13, 2025 Aug 13, 2025

Hi @dublove ,

for a deeper understanding of Collection vs Array ( with getElements() ) read into:

 

On ‘everyItem( )’ – Part 1
by Marc Autret, June 30, 2010

https://www.indiscripts.com/post/2010/06/on-everyitem-part-1

 

On ‘everyItem( )’ – Part 2
by Marc Autret, July 19, 2010

https://www.indiscripts.com/post/2010/07/on-everyitem-part-2

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Translate
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