Skip to main content
Known Participant
April 9, 2023
Answered

separate text from table

  • April 9, 2023
  • 2 replies
  • 522 views

Hi; There are hundreds of paintings. Is there a way to separate the table and text with paragraphs? I can't get to the table with grep. Thank you.

This topic has been closed for replies.
Correct answer m1b

Hi @uniq1, try this script. It will add a carriage return after every table that doesn't have one.

- Mark

 

 

function main() {

    var doc = app.activeDocument,
        tables = doc.stories.everyItem().tables.everyItem().getElements(),
        counter = 0;

    for (var i = tables.length - 1; i >= 0; i--) {

        var table = tables[i],
            index = table.storyOffset.index;

        if (
            table.storyOffset.parentStory.characters[index + 1].isValid
            && table.storyOffset.parentStory.characters[index + 1].contents != '\u000D'
        ) {
            table.storyOffset.parentStory.insertionPoints[index + 1].contents = '\u000D';
            counter++;
        }

    }

    alert('Added carriage return to ' + counter + ' tables.');

};

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Add carriage return after all tables');

 

 

2 replies

Robert at ID-Tasker
Legend
April 9, 2023

If you have "Question answer" after the table - or anything unique like that - you can use it to add carriage return and then change doubles to singles. 

 

uniq1Author
Known Participant
April 9, 2023

@Robert at ID-Tasker thank you, but the text after the table changes constantly.

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
April 9, 2023

Hi @uniq1, try this script. It will add a carriage return after every table that doesn't have one.

- Mark

 

 

function main() {

    var doc = app.activeDocument,
        tables = doc.stories.everyItem().tables.everyItem().getElements(),
        counter = 0;

    for (var i = tables.length - 1; i >= 0; i--) {

        var table = tables[i],
            index = table.storyOffset.index;

        if (
            table.storyOffset.parentStory.characters[index + 1].isValid
            && table.storyOffset.parentStory.characters[index + 1].contents != '\u000D'
        ) {
            table.storyOffset.parentStory.insertionPoints[index + 1].contents = '\u000D';
            counter++;
        }

    }

    alert('Added carriage return to ' + counter + ' tables.');

};

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Add carriage return after all tables');

 

 

uniq1Author
Known Participant
April 9, 2023

It worked perfectly. Thank you @m1b 

m1b
Community Expert
Community Expert
April 9, 2023

Great! You're welcome.