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

Help me with Script to get text of indesign links

Explorer ,
Jul 13, 2024 Jul 13, 2024

Copy link to clipboard

Copied

Hello!
Could anyone help me with creating a script?
I've tried everything, but I always had mistakes or it didn't go the way I expected.
I have an indesign file with many links to other indesign files. These links are "shuffled" into my larger file, and are activity pages. On each of these links (activity pages), there is a text box applied with the "activity" paragraph style that acts as an identifier.
I need a script that in my "shuffle file", it goes through all the pages in that file and opens the links that are inserted on each page and tells me the text that exists there and has the paragraph style applied. My goal is to identify what activity is included on each page of my jumbled file.
At the end, generate a txt containing the information: Scrambled file page: XX + Text copied from link file page.

TOPICS
Bug , Experiment , How to , Scripting

Views

555

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

Community Expert , Jul 20, 2024 Jul 20, 2024

Thanks @eusoujpg, those demo files are helpful. You didn't include the expected output, so I will go by your instructions as best I can. Here is a script that collects the info and shows it, in CSV format, in an alert box. You can past in Excel, or change script to save to text file, etc.

- Mark

/**
 * @file Show Activities Info.js
 *
 * Displays linked indesign document information
 * including page number, link name, and content
 * of first 'activities' paragraph-styled paragraph
 * on the lin
...

Votes

Translate

Translate
Community Expert ,
Jul 13, 2024 Jul 13, 2024

Copy link to clipboard

Copied

Hi @eusoujpg can you post your demo files? Before and after script? - 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
Explorer ,
Jul 15, 2024 Jul 15, 2024

Copy link to clipboard

Copied

Yes!
Attached files.

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 ,
Jul 20, 2024 Jul 20, 2024

Copy link to clipboard

Copied

Could help? Any suggestion?

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 ,
Jul 20, 2024 Jul 20, 2024

Copy link to clipboard

Copied

@eusoujpg 

 

Is this the result you are looking for?

(tab)File Name(tab)Page Name(tab)Contents

RobertatIDTasker_0-1721501956942.png

(attached)

 

The solution is based on my tool - it's PC only and is not free - but I can give you access to the full version for a few days - now or in the future.

 

 

1st Task - extracts all linked INDD files from the main document:

RobertatIDTasker_1-1721502084320.png

and the result:

RobertatIDTasker_5-1721502187586.png

RobertatIDTasker_7-1721502226280.png

 

2nd Task - run in BatchMode on all extracted links:

RobertatIDTasker_2-1721502102409.png

 

3rd Task - saving report:

RobertatIDTasker_3-1721502119663.png

RobertatIDTasker_8-1721502313942.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
Community Expert ,
Jul 20, 2024 Jul 20, 2024

Copy link to clipboard

Copied

Here is LINK to a bit more detailed explanation of the process.

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 ,
Jul 26, 2024 Jul 26, 2024

Copy link to clipboard

Copied

Thanks for the suggestion. I'll see how you could sign up!

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 ,
Jul 26, 2024 Jul 26, 2024

Copy link to clipboard

Copied

LATEST
quote

Thanks for the suggestion. I'll see how you could sign up!


By @eusoujpg

 

What do you mean? 

 

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 ,
Jul 20, 2024 Jul 20, 2024

Copy link to clipboard

Copied

Thanks @eusoujpg, those demo files are helpful. You didn't include the expected output, so I will go by your instructions as best I can. Here is a script that collects the info and shows it, in CSV format, in an alert box. You can past in Excel, or change script to save to text file, etc.

- Mark

/**
 * @file Show Activities Info.js
 *
 * Displays linked indesign document information
 * including page number, link name, and content
 * of first 'activities' paragraph-styled paragraph
 * on the linked page.
 *
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/help-me-with-script-to-get-text-of-indesign-links/m-p/14750067
 */
function main() {

    var doc = app.activeDocument,
        links = doc.links;

    var indds = [];

    // step 1: gather the indd links

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

        if (
            links[0].parent.itemLink
            && 'InDesign Format Name' === links[i].parent.itemLink.linkType
        )
            indds.push({ link: links[i], index: i, page: links[i].parent.parentPage });

    }

    // sort by Page index
    indds.sort(function (a, b) { return a.page.documentOffset - b.page.documentOffset });

    // step 2: gather the text of the activity

    app.findGrepPreferences = NothingEnum.NOTHING;

    for (var i = 0, indd, f, d, p, found; i < indds.length; i++) {

        indd = indds[i];
        indd.contents = '-- activity not found --';

        f = File(indd.link.filePath);

        if (!f.exists)
            continue;

        d = app.open(f, false);

        app.findGrepPreferences.appliedParagraphStyle = 'activity';

        p = d.pages.itemByName(String(indd.link.parent.pageNumber));

        if (!p.isValid)
            continue;

        found = d.findGrep();

        for (var j = 0; j < found.length; j++)
            if (found[j].parentTextFrames[0].parentPage === p)
                indd.contents = found[j].contents.replace(/[\n\r]/g, ' ');

        d.close(SaveOptions.NO);
        d = null;

    }

    // step 3: output

    var output = ['Page,Filename,Contents'];

    for (var i = 0, indd; i < indds.length; i++) {

        indd = indds[i];

        output.push(indd.page.name + ',' + indd.link.name + ',' + indd.contents);

    }

    alerter('Activities', output.join('\n'), 1000, 500);

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Show Activities');


/**
 * Show text in a multiline edit text field.
 * @param {String} title - the title of the alerter
 * @param {String|Array} obj - the text content (array of strings will work)
 * @param {Number} [width] - the dialog width
 * @param {Number} [height] - the dialog height
 */
function alerter(title, obj, width, height) {

    width = width || -1;
    height = height || -1;

    if (obj instanceof Array)
        obj = obj.join("\r");

    var w = new Window("dialog", title),
        et = w.add("edittext", undefined, obj, { multiline: true, scrolling: true }),
        closeButton = w.add("button", undefined, "Close", { name: "ok", alignment: ['right', 'center'] });

    et.maximumSize.height = w.maximumSize.height - 100;
    et.minimumSize.height = 350;
    et.minimumSize.width = 350;
    et.preferredSize = [width, height];

    w.show();

};

 

By the way, here is the output using your demo documents:

Page,Filename,Contents
1,ACTIVITS_2.indd,activity 1 “xxxx”
2,ACTIVITS_1.indd,activity 1 “xxxx”
3,ACTIVITS_2.indd,activity 2 “xxxx”
4,ACTIVITS_1.indd,activity 2 “xxxx”
5,ACTIVITS_3.indd,activity 1 “xxxx”
6,ACTIVITS_2.indd,activity 3 “xxxx”
7,ACTIVITS_3.indd,activity 2 “xxxx”
8,ACTIVITS_3.indd,activity 3 “xxxx”
9,ACTIVITS_1.indd,activity 3 “xxxx”

 

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 ,
Jul 26, 2024 Jul 26, 2024

Copy link to clipboard

Copied

Thank you very much for your help. I will try to adapt it to my original file.

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