if (app.documents.length > 0) {
var myDocument = app.documents[0];
//----------------------------Open Dialog box----------------------------//
var myStylesNames = [];
for (i = 0; i < myDocument.allParagraphStyles.length; i++) {
myStylesNames.push(myDocument.allParagraphStyles.name);
}
var myDialog = app.dialogs.add({
name: "Align to dots script",
canCancel: true
});
with(myDialog.dialogColumns.add()) {
staticTexts.add({
staticLabel: "Choose the paragraph style applied to the cells you want to align on dot"
});
}
with(myDialog.dialogColumns.add()) {
var myDDSTyles = dropdowns.add({
stringList: myStylesNames,
selectedIndex: 0
});
}
var myResult = myDialog.show();
if (myResult == true) {
var myParaStyle = myStylesNames[myDDSTyles.selectedIndex];
}
myDialog.destroy();
//---------------------------- add a tab before (if doesn't exist) ----------------------------//
app.findGrepPreferences = null;
app.changeGrepPreferences = null;
app.findGrepPreferences.properties = {
findWhat: "^(\\d)",
appliedParagraphStyle: myParaStyle,
}
app.changeGrepPreferences.changeTo = "\\t$1";
app.activeDocument.changeGrep();
app.findGrepPreferences = null;
app.changeGrepPreferences = null;
//---------------------------- create array ----------------------------//
var myText = [];
var allText = myDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().getElements();
for (i = 0; i < allText.length; i++) {
if (allText.appliedParagraphStyle.name == myParaStyle) {
myText.push(allText);
}
}
//---------------------------- Set tab alignment and apply to cells ----------------------------//
var tabStopProperties = {
alignment: TabStopAlignment.CHARACTER_ALIGN,
alignmentCharacter: "."
};
for (var i = 0; i < myText.length; i++) {
var cellWidth = myText.parent.width;
var cellLeftInset = myText.parent.leftInset;
var cellRightInset = myText.parent.rightInset;
var position = (cellWidth - cellRightInset - cellLeftInset - 1.058) / 2;
myText.tabStops.everyItem().remove();
myText.tabStops.add();
myText.tabStops[0].properties = tabStopProperties;
myText.tabStops[0].position = position;
}
} else {
alert("Please open a document");
}