8 Replies Latest reply on Sep 22, 2011 6:55 AM by andreasf

    Please: Need quick tips how to Script Indesign to clear ALL style overrides

    andreasf

      Hi,

       

      Having spent hours trying to figure out this myself I need your help.

       

      I'm trying to write a script that tells Indesign to

       

      Clear all local style overrides in both character and paragraph styles

       

      Need to work on whatever style

       

      I desperately need this, so that I can assign a shortcut to Indesign to fix this.

       

      Please post the whole code – from first to last line – and tell me what I should name the file (js or jsx).

       

      I am kind of new to scripts so its all jibberish to me.

       

      Hope someone can help me out.

       

      (Found this post but cant figure out how to do this, I just get script errors in Indesign, but that can be because I dont have the whole script

      http://forums.adobe.com/message/3926903#3926903)

        • 1. Re: Please: Need quick tips how to Script Indesign to clear ALL style overrides
          Harbs. Level 6

          app.documents[0].stories.everyItem().clearOverrides()

           

          (This will not get footnotes or tables.)

           

          Harbs

          • 2. Re: Please: Need quick tips how to Script Indesign to clear ALL style overrides
            andreasf Level 1

            Great!!!

             

            How can I get the script to affect:

             

            1. Only selected paragraph (if possible)

            2. Only selected textbox/es (if possible)

             

            If that can be done, this would be a real lifesaver for me.

            • 3. Re: Please: Need quick tips how to Script Indesign to clear ALL style overrides
              Haakenlid Level 3

              Try this script. It goes through your selection and clears overrides from selected text and text frames.

               

              var mySelection;
              for (var i = 0; i < app.selection.length; i++){
                  mySelection = app.selection[i];
                  if (mySelection instanceof TextFrame){
                      mySelection.paragraphs.everyItem().clearOverrides();
                  } else if (mySelection.hasOwnProperty("clearOverrides")){
                      mySelection.clearOverrides();
                  }
              }
              
              • 4. Re: Please: Need quick tips how to Script Indesign to clear ALL style overrides
                andreasf Level 1

                Thanks, but unfortunately doesn work for me. Problem is Indesign doesnt recognize the text as beeing overridden, even if though it is.

                 

                The text is placed into indesign by an automated 3:rd party app. But everytime I must select the text and "force" Indesign to use "PARAGRAPH STYLE NAME", then the next format, clear text format. I do this from the drop-down menu in paragraph style palette.

                 

                Any way this can be scriptable to work whatever the paragraph style is?

                 

                This would be a real lifesaver for me.

                • 5. Re: Please: Need quick tips how to Script Indesign to clear ALL style overrides
                  Haakenlid Level 3

                  Your  app probably creates some character styles and or paragraph styles on import and apply them to the text.
                  Paragraph styles and character styles are not overrides. InDesign doesn't recognize overrides because the styles are not overridden.

                   

                  The text is placed into indesign by an automated 3:rd party app. But everytime I must select the text and "force" Indesign to use "PARAGRAPH STYLE NAME", then the next format, clear text format. I do this from the drop-down menu in paragraph style palette.

                  Why didn't you say so in the first place? Try this code. It will not change paragraph styles, but it will clear all applied character styles.

                   

                   

                  var mySelection;
                  for (var i = 0; i < app.selection.length; i++){
                    mySelection = app.selection[i];
                    if (mySelection.hasOwnProperty("paragraphs")){
                      mySelection.paragraphs.everyItem().appliedCharacterStyle = app.activeDocument.characterStyles[0];
                      mySelection.paragraphs.everyItem().clearOverrides();
                    }
                  }
                  
                  • 6. Re: Please: Need quick tips how to Script Indesign to clear ALL style overrides
                    andreasf Level 1

                    Sorry for that lack of information in previous post.

                     

                    The last script almost solved my issue. Problem is though that it doesnt make the paragraph style respect the setting "apply XXX style after this style" (when the paragraph ends).

                     

                    For example.

                    Paragraph style name is "Times bold" – after this paragraph "Times italic" should follow (as specified in paragraph style).

                     

                    When I apply the script the whole text gets formatted in "Times bold". (Same result even if I just apply the script to first paragraph.)

                     

                    Is this possible to fix with a script? This is a real tedious work for me to do manually really, really many times a day. (The only way to solve it right now is to make object styles, but that's not a really good workaround).

                    • 7. Re: Please: Need quick tips how to Script Indesign to clear ALL style overrides
                      Haakenlid Level 3

                      You can do it like this. This will find the first paragraph style in the selection and apply next style.
                      If you want to run the script on a long story that spans several textframes, you should select the text itself, and not the textframes if you want to apply next style across the frames. In some cases there will be a difference.

                       

                      var mySelection, myParagraph, myParagraphStyle;
                      for (var i = 0; i < app.selection.length; i++){
                        mySelection = app.selection[i];
                        if (mySelection.hasOwnProperty("paragraphs")){
                           myParagraphStyle = mySelection.paragraphs[0].appliedParagraphStyle;
                           for (var j = 0; j <mySelection.paragraphs.length; j++){
                               myParagraph = mySelection.paragraphs[j];
                               myParagraph.appliedParagraphStyle = myParagraphStyle;
                               myParagraphStyle = myParagraphStyle.nextStyle||myParagraphStyle;
                           }
                          mySelection.paragraphs.everyItem().appliedCharacterStyle = app.activeDocument.characterStyles[0];
                          mySelection.paragraphs.everyItem().clearOverrides();
                        }
                      }
                      
                      • 8. Re: Please: Need quick tips how to Script Indesign to clear ALL style overrides
                        andreasf Level 1

                        Great! My first test shows that its working just like expected. Fabulous!