6 Replies Latest reply on Sep 28, 2013 3:01 AM by Peter Kahrel

    Replace small caps with regular text in Indd CS6, js

    Yuliaart Level 1

      Hi,

       

      I need to replace small caps with regular text in Indd cs6 and what I found doesn't work for me:

       

      var myDoc = app.activeDocument;
      myTextFrames = myDoc.textFrames.everyItem();
      
      
      for ( var a = 0; a < myTextFrames.length; a++) {
           myTextFrames(a).paragraphs.item(0).capitalization.SMALL_CAPS = false; 
           }
      

       

       

       

      Thank you.

        • 1. Re: Replace small caps with regular text in Indd CS6, js
          Peter Kahrel Adobe Community Professional & MVP

          Some small errors in your code. Here's what it should be -- changes in red (though I couldn't test right now):

           

          var myDoc = app.activeDocument;
          myTextFrames = myDoc.textFrames.everyItem().getElements();
          
          
          for ( var a = 0; a < myTextFrames.length; a++) {
               myTextFrames[a].paragraphs.item(0).capitalization = Capitalization.SMALL_CAPS; 
               }
          

           

          Peter

          • 2. Re: Replace small caps with regular text in Indd CS6, js
            Peter Kahrel Adobe Community Professional & MVP

            Can't see the red for some reason. Too bad.

            • 3. Re: Replace small caps with regular text in Indd CS6, js
              Yuliaart Level 1

              That worked and worked very well. Thank you.

               

               

              But I discovered one miss on my part that is now I don't know how to fix.

               

               

              I do need every item in the text frame to be adjusted - not only the first one.

              Here is what I have that doesn't work:

               

              var myDoc = app.activeDocument;

              myTextFrames = myDoc.textFrames.everyItem().getElements();

              myTextItems = myTextFrames[a].paragraphs.item.everyItem().getElements();

               

               

              for ( var a = 0; a < myTextFrames.length; a++) {

                  for ( var b = 0; b < myTextFrames[a].paragraphs.items.length; b++) {

                      myTextFrames[a].paragraphs.myTextItems(b).capitalization = Capitalization.NORMAL;

                      }

                   }

               

               

              Thank you.

              • 4. Re: Replace small caps with regular text in Indd CS6, js
                Peter Kahrel Adobe Community Professional & MVP

                Mind your brackets and parentheses:

                 

                myTextFrames[a].paragraphs.myTextItems[b].

                 

                But you don't need any loops at all, you can change capitalisation with a single line:

                 

                app.documents[0].stories.everyItem().capitalization = Capitalization.NORMAL

                 

                Peter

                • 5. Re: Replace small caps with regular text in Indd CS6, js
                  Yuliaart Level 1

                  Actually, thank you, it's perfect and I thought of it too: why to go into nested loops, if all text needs to be converted to Normal, then your approach is the best.

                   

                  But then I realized that I got myself off track. I do need AllCaps remain, etc. I only need to remove SmallCaps. So here what I came up with and it's actually working . I think it is:

                   

                   

                  myTextFrames = myDoc.textFrames.everyItem().getElements();
                  
                  for ( var a = 0; a < myTextFrames.length; a++) {
                      for ( var b = 0; b < myTextFrames[a].words.length; b++) {
                          if (myTextFrames[a].words[b].capitalization == Capitalization.SMALL_CAPS){
                              myTextFrames[a].words[b].capitalization = Capitalization.NORMAL;
                              }
                          }
                  
                      }
                  

                   

                  Thank you.

                  • 6. Re: Replace small caps with regular text in Indd CS6, js
                    Peter Kahrel Adobe Community Professional & MVP

                    Well done. But there is an easier way in fact:

                     

                    app.findGrepPreferences = app.changeGrepPreferences = null;
                    app.findGrepPreferences.capitalization = Capitalization.SMALL_CAPS;
                    app.changeGrepPreferences.capitalization = Capitalization.NORMAL;
                    app.documents[0].changeGrep();
                    

                     

                    Peter