Skip to main content
graemem34292562
Participant
October 20, 2015
Answered

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

  • October 20, 2015
  • 2 replies
  • 2069 views

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.

This topic has been closed for replies.
Correct answer Peter Kahrel

 

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


There is:

 

myRow.startRow = StartParagraph.NEXT_FRAME

 

P.

2 replies

3december
Known Participant
November 9, 2022

Could it be that the script was not working? 

 

Kind regards, 

xavier 

Peter Kahrel
Community Expert
Community Expert
November 9, 2022

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.

3december
Known Participant
November 9, 2022

 

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

Peter Kahrel
Community Expert
Community Expert
October 20, 2015

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

Obi-wan Kenobi
Legend
October 20, 2015

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!

Peter Kahrel
Community Expert
Community Expert
October 20, 2015

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