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

Looking for a Script to Add Rows in Multiple Places in a Table

Community Beginner ,
Dec 30, 2013 Dec 30, 2013

Copy link to clipboard

Copied

Hello all!

I'm new to InDesign Scripting and I have been hunting around trying to find anything that would possibly work, and I just can't quite find it. I hope someone can help!

I have a book that has tons of tables in it. They are all the same table. 2 Columns by 10 rows. Here is my dilemma:

My client wants to add new rows to these tables, specifically:

  • A new row at the beginning of the table
  • A row after the already established 3rd row
  • 3Rows after the already established 9th row

Is this even possible with a script?

(I mention "already established" row, because I'm not sure if once the script adds that first row at the top, if that then changes the numbers of the rest of the rows -- and so on when more are added.)

Any help would be MUCH appreciated.

TOPICS
Scripting

Views

1.2K

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

Enthusiast , Dec 30, 2013 Dec 30, 2013

Hi,

what is a book for you? One document or a real Indesign-book-file with several documents?

One document:

var curDoc = app.activeDocument;

var allTables = curDoc.stories.everyItem().tables.everyItem().getElements();

for ( var t = 0; t < allTables.length; t++ ) {

    var curTable = allTables;

    var allRows = curTable.rows;

    curTable.rows.add(LocationOptions.AFTER, allRows[8]);

    curTable.rows.add(LocationOptions.AFTER, allRows[8]);

    curTable.rows.add(LocationOptions.AFTER, allRows[8]);

    curTa

...

Votes

Translate

Translate
Enthusiast ,
Dec 30, 2013 Dec 30, 2013

Copy link to clipboard

Copied

Hi Tiggermn8278

This might help you a bit, I hope.

This is for the first table.

*********************************************************

main();

exit();

function main() {

    var myDoc = app.activeDocument;

// first you need something to get hold of the tables

// this is for the first talble in the first story

    var myStory = myDoc.stories[0];

    var myTable = myStory.tables[0];

    var ninthRow = myTable.rows[9];

    myTable.rows.add(LocationOptions.BEFORE, ninthRow);

    var ninthRow = myTable.rows[9];

    myTable.rows.add(LocationOptions.BEFORE, ninthRow);

    var ninthRow = myTable.rows[9];

    myTable.rows.add(LocationOptions.BEFORE, ninthRow);

    var thirdRow = myTable.rows[3];

    myTable.rows.add(LocationOptions.BEFORE, thirdRow);

    myTable.rows.add(LocationOptions.AT_BEGINNING);

}

*********************************************************

kind regards

Dani (from Switzerland)

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
Enthusiast ,
Dec 30, 2013 Dec 30, 2013

Copy link to clipboard

Copied

Hi,

what is a book for you? One document or a real Indesign-book-file with several documents?

One document:

var curDoc = app.activeDocument;

var allTables = curDoc.stories.everyItem().tables.everyItem().getElements();

for ( var t = 0; t < allTables.length; t++ ) {

    var curTable = allTables;

    var allRows = curTable.rows;

    curTable.rows.add(LocationOptions.AFTER, allRows[8]);

    curTable.rows.add(LocationOptions.AFTER, allRows[8]);

    curTable.rows.add(LocationOptions.AFTER, allRows[8]);

    curTable.rows.add(LocationOptions.AFTER, allRows[2]);

    curTable.rows.add(LocationOptions.AT_BEGINNING);

}

Several closed documents in a book file:

This assumes, that only one book file is open!

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

var curBook = app.books[0];

var allDocuments = curBook.bookContents;

for ( var n = 0; n< allDocuments.length; n++ ) {

    var curDoc = app.open( File( allDocuments.fullName ) );  

 

    var allTables = curDoc.stories.everyItem().tables.everyItem().getElements();

    for ( var t = 0; t < allTables.length; t++ ) {

        var curTable = allTables;

        var allRows = curTable.rows;

        curTable.rows.add(LocationOptions.AFTER, allRows[8]);

        curTable.rows.add(LocationOptions.AFTER, allRows[8]);

        curTable.rows.add(LocationOptions.AFTER, allRows[8]);

        curTable.rows.add(LocationOptions.AFTER, allRows[2]);

        curTable.rows.add(LocationOptions.AT_BEGINNING);

    } 

    // optional

    // curDoc.save();

    // curDoc.close();

}  

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

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 Beginner ,
Dec 30, 2013 Dec 30, 2013

Copy link to clipboard

Copied

THANK YOU! It was for one document, so that script worked PERFECTLY! It was EXACTLY what I was looking for!

This just saved me HOURS of manually adding rows to over 300+ tables!

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
Explorer ,
Sep 26, 2017 Sep 26, 2017

Copy link to clipboard

Copied

Hi.

I am looking for is more than simple. I think.

Iff I needed add only one roow at the botton in all tables in my active document?

Is it possible?

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
Engaged ,
Sep 26, 2017 Sep 26, 2017

Copy link to clipboard

Copied

LATEST

Hi,

Try this!!

curTable.rows.add(LocationOptions.AT_END);

Adobe InDesign CS6 (8.0) Object Model JS: Layer

Thanks,

Prabu

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

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