Copy link to clipboard
Copied
I want to create a script in InDesign that clears my overrides on one specific paragraph style. Any ideas?
1 Correct answer
Hi mikej3204
I've put together a few lines.
Try them and see if they work for you.
kind regards
Daniel (from Switzerland)
...main();
exit();
// needs some refinement to fit your needs
function main() {
// try it with both functions
// doitWithSelection();
doitWithAllParagraphs();
alert("Information\nI've done my job, what about yours");
}
// 1. Select a paragraph (click 4 times into text)
// .2 start the program
function doitWithSelection() {
var myDoc = app.activeDocument;
if
Copy link to clipboard
Copied
Hi mikej3204
I've put together a few lines.
Try them and see if they work for you.
kind regards
Daniel (from Switzerland)
main();
exit();
// needs some refinement to fit your needs
function main() {
// try it with both functions
// doitWithSelection();
doitWithAllParagraphs();
alert("Information\nI've done my job, what about yours");
}
// 1. Select a paragraph (click 4 times into text)
// .2 start the program
function doitWithSelection() {
var myDoc = app.activeDocument;
if (myDoc != null) {
var myParaSel = myDoc.selection[0];
if (myParaSel.constructor.name == "Paragraph") {
// you have to change the "Test" with your paragraphstyle where you want to clear all overrides
if (myParaSel.appliedParagraphStyle == myDoc.paragraphStyles.item("Test") ) {
myParaSel.clearOverrides();
}
}
else {
alert("Information\nNo paragraph selected");
}
}
}
function doitWithAllParagraphs() {
var myDoc = app.activeDocument;
if (myDoc != null) {
var paras = myDoc.stories.everyItem().paragraphs.everyItem().getElements();
for (var i = 0; i < paras.length; i++) {
myParaSel = paras;
// you have to change the "Test" with your paragraphstyle where you want to clear all overrides
if (myParaSel.appliedParagraphStyle == myDoc.paragraphStyles.item("Test") ) {
myParaSel.clearOverrides();
}
} // for the for loop
}
}
Copy link to clipboard
Copied
Ok,
I got it to work in a text box, but I want it to reformat within a table. I assume that changes a lot?
Also, I will want it to do it to multiple styles, how would I go about adding styles to that script?
Thank you very much!!!!
-MK
Copy link to clipboard
Copied
For the multiple styles replace
if (myParaSel.appliedParagraphStyle == myDoc.paragraphStyles.item("Test") ) {
myParaSel.clearOverrides();
}
with
switch (myParaSel.appliedParagraphStyle) {
case myDoc.paragraphStyles.item("Test"): ;
case myDoc.paragraphStyles.item("Test1"): ;
case myDoc.paragraphStyles.item("…"): ;
// and so on
myParaSel.clearOverrides();
}
If you want to find paragraphs in an table try the following lines
I only changed it for one function
function doitWithAllParagraphs() {
var myDoc = app.activeDocument;
if (myDoc != null) {
var paras = myDoc.stories.everyItem().paragraphs.everyItem().getElements();
// you have to test if there is any table
if (myDoc.stories.everyItem().tables.length > 0) {
var paras = myDoc.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().getElements();
for (var i = 0; i < paras.length; i++) {
myParaSel = paras;
switch (myParaSel.appliedParagraphStyle) {
case myDoc.paragraphStyles.item("Test"): ;
case myDoc.paragraphStyles.item("Test1"): ;
myParaSel.clearOverrides();
}
}
} // for the for loop
else alert("Information\nNot Table found");
}
}

