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

How to get cells in a selected text frame

Community Expert ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

Hi, I have an ExtendScript question.
When there are connected text frames and one table object straddles both sides, I want to get the cells in the selected text frame.
In your screenshot, you want to get cells 6-10.
What is a good way to do this.
Thanks.

 

スクリーンショット 2022-07-05 12.31.03.png

TOPICS
Scripting

Views

293

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

Community Expert , Jul 05, 2022 Jul 05, 2022

Hi @ajabon grinsmith ,

the short answer is no. You can determine the first frame of the parentTextFrames array.

And that's it. Just like you did this.

 

The more interesting question would be:

How would you get the text frame if some or all cells in that table are graphic cells?

 

One idea:

 

Insert unique labels to every cell of the table.

Use cell.insertLabel( keystring , valuestring ) for this.

Duplicate the text frame you selected.

Then you can determine which cells are in by looking at all

...

Votes

Translate

Translate
Community Expert , Jul 12, 2022 Jul 12, 2022

A table sits in a paragraph. When a table breaks across frames, each line of the table's paragraph contains the part of the table that sits in a frame, and each line is in the first paragraph of each frame. The part of the table that sits in the frame you selected is in your selected frame's first paragraph.

 

But you don't have direct access to that part. To determine which cells are in the selected frame, you have to get a reference to the whole table, get all the cells, and cycle through them

...

Votes

Translate

Translate
Community Expert ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

One idea.
It will take processing time.
If all cells are looped through, the stored text frames can be obtained. Determine if the text frame is selected.

I wonder if there is an approach that uses the text frame as the starting point.

スクリーンショット 2022-07-05 14.37.33.png

var sel = app.selection[0];
var ary = [];
var cells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();

for(var i = 0; i < cells.length; i++){
    if(cells[i].texts[0].parentTextFrames[0] == sel){
        ary.push(cells[i]);
        }
    }

for(i = 0; i < ary.length; i++){
    $.writeln(ary[i].texts[0].contents);
    }

 

Votes

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
Community Expert ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

Hi @ajabon grinsmith ,

the short answer is no. You can determine the first frame of the parentTextFrames array.

And that's it. Just like you did this.

 

The more interesting question would be:

How would you get the text frame if some or all cells in that table are graphic cells?

 

One idea:

 

Insert unique labels to every cell of the table.

Use cell.insertLabel( keystring , valuestring ) for this.

Duplicate the text frame you selected.

Then you can determine which cells are in by looking at all cells of the table of that duplicated frame.

Use cell.extractLabel( keystring ) and see what value string is returned.

 

Keep in mind that tables can come along with header and footer rows.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

 

Votes

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
Community Expert ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

Laubender,

Thank you.
I had omitted to tell you that the graphic cell was omitted because it is not used in this project.

The labeling and duplication method has always been the way to go. This is still the most stable and versatile.

Votes

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
Community Expert ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

it will take processing time.

 

Hi @ajabon grinsmith , seems like you could limit the size of the cell collection by getting the table or tables in the selection’s parentStory, rather than all the document’s tables:

 

var cells = sel.parentStory.tables[0].cells.everyItem().getElements();

 

Votes

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
Community Expert ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

rob, 

Thank you, you are absolutely right.
But that's like picking a corner of the lunchbox.
What I am looking for now is not the completeness of the sample code, but a means of approaching the cell.

Votes

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
Community Expert ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

And rob.
Your answer did not satisfy me. It is just a frying pan. So I can't give you the correct answer.
I'm done with this question, so I've decided that Laubender's is the correct answer.
Don't be offended. Best regards!

Votes

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
Community Expert ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

A table sits in a paragraph. When a table breaks across frames, each line of the table's paragraph contains the part of the table that sits in a frame, and each line is in the first paragraph of each frame. The part of the table that sits in the frame you selected is in your selected frame's first paragraph.

 

But you don't have direct access to that part. To determine which cells are in the selected frame, you have to get a reference to the whole table, get all the cells, and cycle through them, checking whether a cell's insertion point's parent text frame is your selected frame. (This is problematic with overset cells, so you should check that first.)

 

Like this:

 

 

frame = app.selection[0];
// Get all the cells in the table
cells = frame.paragraphs[0].tables[0].cells.everyItem().getElements();
sel = [];
// Collect the cells that are in the frame
for (i = 0; i < cells.length; i++) {
  if (cells[i].insertionPoints[0].parentTextFrames[0] == frame) {
    sel.push (cells[i]);
  }
}

// Display the content of the selected cells
for (i = 0; i < sel.length; i++) {
  $.writeln (sel[i].contents);
}

 

 

P.

Votes

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
Community Expert ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

LATEST

Peter, 
Your view is in line with mine.
As Laubender indicated, the code you provided is most convincing, considering also that the cell is not necessarily a text cell. I will definitely refer to it.
Awesome thanks.

Votes

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