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>
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');
/**
...
Copy link to clipboard
Copied
Hi @Phil28637952i5ng, please post a sample document showing example table with and without the leader dots. That will help us answer.
- Mark
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.
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;
};
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!
Copy link to clipboard
Copied
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. 🙂