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

Set InDesign table "Keep with next row" via a script

New Here ,
Oct 20, 2015 Oct 20, 2015

Copy link to clipboard

Copied

I am new to InDesign JavaScript scripting. I am importing XML into InDesign tables and want to set the table cell "keep options" to "Keep with next row" via a JavaScript script.

The aim of the script would be to search for a paragraph style, (Head1) in a table and apply "Keep with next row" = "true" creating a new page break.

Any complete examples with a short explanation would be welcome.

TOPICS
Scripting

Views

1.1K

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 1 Correct answer

Community Expert , Nov 09, 2022 Nov 09, 2022

There is:

 

myRow.startRow = StartParagraph.NEXT_FRAME

 

P.

Likes

Translate

Translate
Community Expert ,
Oct 20, 2015 Oct 20, 2015

Copy link to clipboard

Copied

Here you are. Hope it's clear.

// Reset the Find/Change dialog

app.findTextPreferences = null;

// Set the targeted paragraph style

app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item ('Head1');

// Find all occurrences of the paragraph style

found = app.activeDocument.findText();

// and go through all found items

for (i = 0; i < found.length; i++) {

  // If the found instance is in a cell

  if (found.parent instanceof Cell) {

    // set the cell's parent row to keep with the next row

    found.parent.parentRow.keepWithNextRow = true;

  }

}

Peter

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
LEGEND ,
Oct 20, 2015 Oct 20, 2015

Copy link to clipboard

Copied

Hi Peter,

A comment as an aside:

The table widows / orphans management seems apparently only to be included in InDesign as a check box option "Keep lines together" in the "Cell Options", "Rows and Columns" tab. While it would seem to me better that we can choose this in table style itself.

Is there a possibility, via [JS], to check this option globally ("story", document or book) or selecting a table through a kind of dialog: beginning of the table = "2" solidarity lines ; end of the table = "3" lines solidarity? ... Like that exists for paragraphs. And this, whatever styles applied cells [header, footer, current cell].

Once one or all formatted tables, the launch of the script would lock this choice, facilitating the layout [next step], the op no longer having to worry about this.

Thanks in advance for your comment!

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
Community Expert ,
Oct 20, 2015 Oct 20, 2015

Copy link to clipboard

Copied

Sure, such a script wouldn't be too difficult to write.

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
LEGEND ,
Oct 20, 2015 Oct 20, 2015

Copy link to clipboard

Copied

Thanks Peter!

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
Explorer ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

Could it be that the script was not working? 

 

Kind regards, 

xavier 

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
Community Expert ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

It certainly isn't working. Problem is (as ever) the transfer of the forum messages, which removed indexes. This fragment in the script:

 

if (found.parent instanceof Cell) {
  // set the cell's parent row to keep with the next row
  found.parent.parentRow.keepWithNextRow = true;

 

should be like this (add [i] to 'found' in two instances):

 

if (found[i].parent instanceof Cell) {
  // set the cell's parent row to keep with the next row
  found[i].parent.parentRow.keepWithNextRow = true;

 

 

P.

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
Explorer ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

 

Yes, I figured it out. Thank you. Is there a javascript command that can automate to start the row on a next frame instead of the option to keep the rows together? 

Kind regards, 

xavier

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
Community Expert ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

There is:

 

myRow.startRow = StartParagraph.NEXT_FRAME

 

P.

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
Explorer ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

LATEST

Thank you ! 

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