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

Is there an InDesign DOM flowchart? Getting contents of text frames on a specific page.

Enthusiast ,
Oct 09, 2023 Oct 09, 2023

Copy link to clipboard

Copied

I reference the flowchart for Illustrator quite a bit to understand structure, but I'm just wondering if one is available for InDesign? Maybe it's too fluid, but in general, I'm scripting getting the contents of a text frame based on the page number. Stories seem to hold the most info, but I don't entirely understand where they are in the structure. So I think my best bet is:

pageItems = app.activeDocument.pages.item(1).allPageItems
for(var i = 0; i < pageItems.length; i++){
        var curPI = pageItems[i];
        var curType = curPI.constructor.name;
        if(curType == "TextFrame") alert(curPI.parentStory.contents)
}

I don't entirely understand how parentStory or parentPage works... is there a more straightforward way than I've found?

FWIW I'm determining which page I pull text frames from, based on the first findGrep result, but have not complicated this example with that piece.

TOPICS
Scripting

Views

260

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

Hi,

 

this is the closest thing in terms of a flowchart I know of

http://www.indesignjs.de/auflage2/wp-content/uploads/2015/04/InDesign_Skripting_Kurzreferenz.pdf

Votes

Translate

Translate
Community Expert ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

Hi @wckdtall , A textFrame has parentPage and parentStory properties

 

Here's the API

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#TextFrame.html

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

Copy link to clipboard

Copied

Thanks! I do use the API documentation, but I'm specifically looking for the flow chart so I know how these things interact a little bit clearer.

The example you provide is certainly an alternative option to grep, but would still require Parent Story in order to get the contents regardless of overset text.

What I've chosen to do is use allPageItems, because it ignores object structure, and just needs to be evaluated for the object you're looking for. I think this is the most straightforward way, but again I feel like a flowchart would help if it exists

var theDoc = app.activeDocument;
    app.findGrepPreferences.findWhat = "(?i).*TABLE OF CONTENTS.*";
//Check for a result or there will be an error setting variables
    if (theDoc.findGrep().length > 0) {
        //Set the Target Number based off Document Offset starts at 0
        var tgtPgNum = theDoc.findGrep()[0].parentTextFrames[0].parentPage.documentOffset;
        //Set Page to Target
        var tgtPage = theDoc.pages.item(tgtPgNum);
        var tgtPI = tgtPage.allPageItems;
        var tgtFind = [];
        for (var c = 0; c < tgtPI.length; c++) {
            var curPI = tgtPI[c];
            var curType = curPI.constructor.name;
            if (curType == "TextFrame") tgtFind.push(curPI.parentStory.contents);
        }
}
//Dump contents to an alert for testing.
alert(tgtFind);

 

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

Copy link to clipboard

Copied

This does the same without looping through the page items—parentTextFrames[0] is the result’s first text frame:

 

 

 


//the search result array
var res = getGrepSearch("(?i).*TABLE OF CONTENTS.*")

for (var i = 0; i < res.length; i++){
    alert("Result on page " + (res[i].parentTextFrames[0].parentPage.documentOffset+1) +"\rText Frame Contents\r\r" + res[i].parentTextFrames[0].contents )
};   


/**
* Gets results of a grep search as an array 
* @ param grep to search for 
* @ returns result array 
*/
function getGrepSearch(fp){
    app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
    app.findGrepPreferences.findWhat = fp;
    return app.activeDocument.findGrep()
}

 

 

 

Screen Shot 9.png

 

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

Copy link to clipboard

Copied

Thanks. I do want to get all text frames within a page that says Table of Contents, so finding the page and then looping I think is the correct approach.

Often I'll be given a document that has "Table of Contents" in a frame by itself, and then the actual page list in a separate frame. I'm not worried about them being in the correct order at this time, again more just trying to understand to understand structure if a flow chart existed, but I'm not aware of one.

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

Copy link to clipboard

Copied

I think https://www.indesignjs.de is the most comprehensive API—I’m not aware of a flowchart

 

I do want to get all text frames within a page that says Table of Contents,

You can also use:

parentTextFrames[0].parentPage.textFrames.everyItem().contents

to get all the text frames’ contents as an array. So maybe this?

 

//the search result array
var res = getGrepSearch("(?i).*TABLE OF CONTENTS.*")
var c;
for (var i = 0; i < res.length; i++){
    c = res[i].parentTextFrames[0].parentPage.textFrames.everyItem().contents;
    alert("Text Frame Contents:\r" + c)
    //returns an array of contents of all the text frames on the page with the found text

};   


/**
* Gets results of a grep search as an array 
* @ param grep to search for 
* @ returns result array 
*/
function getGrepSearch(fp){
    app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
    app.findGrepPreferences.findWhat = fp;
    return app.activeDocument.findGrep()
}

 

Screen Shot 11.png

 

 

 

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

Copy link to clipboard

Copied

EveryItem still seems to rely on structure unfortunately, and will not capture textFrames within groups.

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

Copy link to clipboard

Copied

You probably want to use the found text’s parentTextFrames property. Something like this

 

 

//the search result array
var res = getTextSearch("Hello World")

for (var i = 0; i < res.length; i++){
    $.writeln("A search result starts on page " + res[i].parentTextFrames[0].parentPage.name)
    //returns
    //A search result starts on page 4
    //A search result starts on page 5
};   


/**
* Gets results of a text search as an array 
* @ param text to search for 
* @ return result array 
*/
function getTextSearch(fp){
    app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
    app.findChangeTextOptions.properties = {includeHiddenLayers:true, includeLockedLayersForFind:true, includeLockedStoriesForFind:true, includeMasterPages:true} 
    app.findTextPreferences.findWhat = fp;
    return app.activeDocument.findText()
}

 

 

 

Screen Shot 3.png

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

Copy link to clipboard

Copied

Hi,

 

this is the closest thing in terms of a flowchart I know of

http://www.indesignjs.de/auflage2/wp-content/uploads/2015/04/InDesign_Skripting_Kurzreferenz.pdf

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

Copy link to clipboard

Copied

LATEST

Thanks! Definitely what seems to be an all inclusive a flowchart! If nothing else, it's a great quick referene to see what attributes can be addressed per object.

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