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

Checking the contents of textFrame with a table

Explorer ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

Hi

 

How to check if a text frame contains a table?

What I mean – The table starts on page 1 and ends on page 3. The text frame on page 2 shows the contents.length = 0, but it contains a part of the table. I want to distinguish text frames containig tables and really empty frames.

TOPICS
How to , Scripting

Views

684

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 , May 10, 2023 May 10, 2023

Check parent TextFrame of the InsertionPoint after the table - from there you can check for "empty" TFs in between. 

 

Votes

Translate

Translate
Community Expert , May 11, 2023 May 11, 2023

To check whether a tect frame contains a table or the continuation of a table, check the text frame's paragraph (if it has one):

 

if (frame.paragraphs.length > 0 
  && frame.paragraphs[0].tables.length > 0) {
    // The frame contains a continuation table
}

 

P.

Votes

Translate

Translate
Community Expert ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

Check parent TextFrame of the InsertionPoint after the table - from there you can check for "empty" TFs in between. 

 

ID-Tasker - most powerful tool ever created for InDesign

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 ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

Hi @mateuszp13156491, in case Robert's method doesn't work out, here is another approach:

/**
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/checking-the-contents-of-textframe-with-a-table/m-p/13783085
 */
function main() {

    var doc = app.activeDocument,
        textFrames = doc.textFrames,
        textFramesWithTables = [];

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

        if (textFrames[i].tables[0].isValid)
            textFramesWithTables = textFramesWithTables.concat(textFramesOfTable(textFrames[i].tables[0]));

    }

}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Do Script');


/**
 * Returns textframes containing the table.
 * @author m1b
 * @version 2023-05-10
 * @param {Table} table - an Indesign Table.
 * @returns {Array<TextFrame>}
 */
function textFramesOfTable(table) {

    var textFrames = [],
        id;

    for (var r = 0; r < table.rows.length; r++) {

        var tf = table.rows[r].cells[0].insertionPoints[0].parentTextFrames[0];

        if (
            tf.isValid
            && tf.id !== id
        ) {
            textFrames.push(tf)
            id = tf.id;
        }

    }

    return textFrames;

};

 I figure if you explicitly get the textframes of the table, you can go from there.

- Mark

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 ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

Yeah, was thinking about the same as well - getting parent TF for the Cells in the table - which should give better results. 

 

ID-Tasker - most powerful tool ever created for InDesign

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 ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

Great! I,ve tried and that is my method:

var a = app.selection[0].id;
var b = app.selection[0].insertionPoints[0].parentTextFrames[0].id;

 

if a != b the frame contains a part of the table

 

Thank You Robert and thank You Mark for the script.

 

Regards

Mateusz

 

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 ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

What is your selection? 

 

I think you've misunderstood my idea? 

 

ID-Tasker - most powerful tool ever created for InDesign

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 ,
May 11, 2023 May 11, 2023

Copy link to clipboard

Copied

@mateuszp13156491 are you sure this works? I couldn't get it to work for me.

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 ,
May 11, 2023 May 11, 2023

Copy link to clipboard

Copied

LATEST

@Robert Tkaczyk your idea works fine.

var firstFrame = table.storyOffset.parentTextFrames[0],
    lastFrame = firstFrame.insertionPoints.nextItem(table.storyOffset).parentTextFrames[0];

var tableFrames = [],
    currentFrame = firstFrame;

while (currentFrame.nextTextFrame != undefined) {
    tableFrames.push(currentFrame);
    currentFrame = currentFrame.nextTextFrame

    if (currentFrame.id === lastFrame.id) {
        tableFrames.push(currentFrame);
        break;
    }

}

$.writeln(tableFrames);

 

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 ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

I think you should use @m1b approach and build and check collection of TFs that are parents for your table - sometimes TF can be empty because text is overset or break character is used of ParaStyle definition forces text to start on even / odd pages.

 

Unless of course you know what you have in your Story. 

 

ID-Tasker - most powerful tool ever created for InDesign

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 ,
May 11, 2023 May 11, 2023

Copy link to clipboard

Copied

To check whether a tect frame contains a table or the continuation of a table, check the text frame's paragraph (if it has one):

 

if (frame.paragraphs.length > 0 
  && frame.paragraphs[0].tables.length > 0) {
    // The frame contains a continuation table
}

 

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 ,
May 11, 2023 May 11, 2023

Copy link to clipboard

Copied

Very nice, indeed! 🙂

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