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

Scripts for clearing style overrides

New Here ,
May 15, 2015 May 15, 2015

I want to create a script in InDesign that clears my overrides on one specific paragraph style. Any ideas?

TOPICS
Scripting
726
Translate
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

Enthusiast , May 15, 2015 May 15, 2015

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

...
Translate
Enthusiast ,
May 15, 2015 May 15, 2015

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

    }

}

Translate
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
New Here ,
May 15, 2015 May 15, 2015

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

Translate
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
Enthusiast ,
May 15, 2015 May 15, 2015
LATEST

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");

    }

}

Translate
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