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

How to create leader dots in table cells with a script in InDesign?

Explorer ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Hi all, I'm hoping I could get some assistance with a task I want to accomplish. 

I have a table with values inserted at each cell. I'd like to fill the remaining space in each cell with leader dots. I know how to do this in the GUI, but I need a script that can do this as well. 

 

Two issues I'm having:

- I'm finding it difficult to determine the space left over for the leader dots to fill.

- I'm having trouble finding a way to directly insert leader dots with a script. Maybe I have to insert a placeholder and convert with some GREP command?

 

Thanks in advance!

 

<Title renamed by moderator>

TOPICS
How to , Scripting

Views

302

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 , Mar 21, 2023 Mar 21, 2023

Those sample files were perfect, thanks. I've written a quick script. First select some cells and run. See what you think. I've set it up so that the cell width doesn't matter—you can change the width later without wrecking the leader.

- Mark

 

function main() {

    var doc = app.activeDocument,
        cells = getCells(doc.selection[0]);

    addLeaderLineTabStopToCells(cells);

}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Add Cell Leader Dots');

/**
 
...

Votes

Translate

Translate
Community Expert ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Hi @Phil 815, please post a sample document showing example table with and without the leader dots. That will help us answer.

- 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 ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Hi @m1b Please see the attached document files for reference of what I'm trying to do via script. The first one (table_without_leader_dots.indd) is the table without any leader dots. The second (table_with_leader_dots.indd) is what I want the table to look like after a script is run on it. To do this manually I had to add a tab ("\t") to each cell and use the type->tabs tool in the GUI to insert the leader dots. I'd like to remove this manual step and programattically add trailing leader dots to each cell via script. 

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 ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Those sample files were perfect, thanks. I've written a quick script. First select some cells and run. See what you think. I've set it up so that the cell width doesn't matter—you can change the width later without wrecking the leader.

- Mark

 

function main() {

    var doc = app.activeDocument,
        cells = getCells(doc.selection[0]);

    addLeaderLineTabStopToCells(cells);

}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Add Cell Leader Dots');

/**
 * To the text of `cells`, add a right-indent-tab
 * and set tab stop with leader.
 * @author m1b
 * @version 2023-03-22
 * @Param {Array<Cell>|Cells} cells - the cells to process.
 */
function addLeaderLineTabStopToCells(cells) {

    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

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

        var cell = cells[i],
            text = cell.texts[0];

        // set up the tab stop
        text.tabStops.add(
            {
                alignment: TabStopAlignment.RIGHT_ALIGN,
                leader: '.',
                position: cell.width,
            }
        );

        // insert right-indent tab
        text.insertionPoints.lastItem().contents = '\u0008';
    }

};

/**
 * Attempts to return array of cell, given an object.
 * @author m1b
 * @version 2023-02-06
 * @Param {InsertionPoint|Text|Cells|Cells|Table} obj - an object related to a Cell.
 * @Returns {Array<Cell>}
 */
function getCells(obj) {

    if (obj == undefined)
        return;

    if (
        obj.hasOwnProperty('cells')
        && obj.cells.length > 0
    )
        return obj.cells;

    if (obj.constructor.name == 'Cell')
        return [obj];

    if (obj.parent.constructor.name == 'Cell')
        return [obj.parent];

    if (obj.constructor.name == 'Table')
        return obj.cells;

};

 

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 ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

@m1b This is great thank you!!! I had to make some small adjustments to the script which may or may not be due to the fact that I'm using UXP, but it's running now! 

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 ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

LATEST

Great! Yeah there are differences with UXP, for example. I think in Indesign UXP you need constructorName instead of constructor.name. Glad you got it working. 🙂

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