17 Replies Latest reply on Mar 17, 2017 11:00 AM by Obi-wan Kenobi

    Applying a same character style to different words inside a text

    danieler36999951

      Hello,

       

      I am typesetting a book on Persian food which has many words that should be italicised. However the formatting has been lost after copying/pasting from MS Word into inDesign and I can't think of having to re-do it manually.

       

      I have a separate list of words that should be italicised, so I was thinking of applying a character style through a GREP style or similar. However, I don't know how to apply a GREP style to a list of words. Do GREP styles only work for single words? I hope not because I have more than 100 to format...

       

      Thanks in advance for any advise.


      Daniele

        • 1. Re: Applying a same character style to different words inside a text
          vinny38 Level 4

          Hi

          My first thought would be FindChangeByList script.

           

          text

          {findWhat:"your word here"}

          {appliedCharacterStyle:"italic"}

          {includeHiddenLayers:true, includeMasterPages:true, includeFootnotes:true, wholeWord:true, caseSensitive:false}

           

          This would require some manipulation to stick your words in the above pattern.

          However, it wouldn't be so difficult to do it in an Excel file.

           

          See what I mean?

           

          However, there might be easier ways, so I would wait for other users answers before going deeper into this process.

          • 2. Re: Applying a same character style to different words inside a text
            SJRiegel Adobe Community Professional & MVP

            If you use Place instead of copy-paste, does that keep your italic formatting?

            • 3. Re: Applying a same character style to different words inside a text
              Obi-wan Kenobi Adobe Community Professional

              Hi,

               

              … When all has already been written … since five years! …

               

              textFile = File(Folder.myDocuments+"/list.txt");  
              if (textFile.open("r") == false)  
                 { alert ("yeah ... that file does not exist"); exit(0); }
                 
              strs = textFile.read ();  
              textFile.close();  
              strs = strs.split("\n");  
              app.findGrepPreferences = app.changeGrepPreferences = null;  
              app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("yourStyle");  
              while (strs.length > 0)  
              {  
              app.findGrepPreferences.findWhat = "\\b"+strs.pop()+"\\b";  
              app.activeDocument.changeGrep();  
              }
              

               

               

              (^/) 

              • 4. Re: Applying a same character style to different words inside a text
                Obi-wan Kenobi Adobe Community Professional

                … with this "French Touch" variant! 

                 

                textFile = File(File($.fileName).parent.fullName + "/list.txt");  
                

                 

                (^/)

                • 5. Re: Applying a same character style to different words inside a text
                  jane-e Adobe Community Professional

                  File > Place by default keeps your formatting such as italics

                   

                  Copy > Paste does not

                   

                  Clipboard Handling Preferences can be changed:

                   

                  as can Import Options for placing:

                  2 people found this helpful
                  • 6. Re: Applying a same character style to different words inside a text
                    contoisj Level 1

                    If you are using CC ( it may also be in earlier versions), you can turn on "All information" under clipboard handling. This will allow you to preserve your word italicizing. From there, you can search for paragraph and character styles using command+f and apply your new character styles, or you can simply format the ones that will be brought in from word.

                     

                    hope that does it!

                    Screen Shot 2017-03-16 at 4.09.33 PM.png

                    • 7. Re: Applying a same character style to different words inside a text
                      Erica Gamet Adobe Community Professional

                      When I import text that has been styled, I choose to strip out the styling (which tends not to be correct or consistent) but preserve local overrides. Then, as was suggested above, do a Find on character styling of italic and Replace it with your italic character style. All of this is assuming the original text is italicized where you need it.

                      textimport.jpeg

                      1 person found this helpful
                      • 8. Re: Applying a same character style to different words inside a text
                        danieler36999951 Level 1

                        Thank you Vinny (and everyone else) for your help. Next time I will try to preserve the original formatting when importing the text!

                         

                        Anyways, the FindChangeByList script method works pretty good in this case!

                         

                        Is there by any chance a way to limit the search within text that has a specific Paragraph Style applied to it?

                         

                        Most of the words that need to be italicised are in the Body text, but I wouldn't want them to be in italics when they appear in chapter titles / subheadings.

                         

                        Thank again!

                        • 9. Re: Applying a same character style to different words inside a text
                          vinny38 Level 4

                          Sure:

                           

                          text

                          {findWhat:"yourword",appliedParagraphStyle:"yourparastyle"}

                          {appliedCharacterStyle:"yourcharstyle"}

                          {includeHiddenLayers:true, includeMasterPages:true, includeFootnotes:true, wholeWord:true, caseSensitive:false}

                           

                           

                          • 10. Re: Applying a same character style to different words inside a text
                            Obi-wan Kenobi Adobe Community Professional

                            Sometimes, I really ask myself if people understand what they are told!

                             

                            (^/)

                            • 11. Re: Applying a same character style to different words inside a text
                              vinny38 Level 4

                              Pas bien compris ton script l'ami.

                              Tu le met où ton fichier .txt?

                              • 12. Re: Applying a same character style to different words inside a text
                                vinny38 Level 4

                                Ah OK c'est bon j'ai capté.

                                C'est effectivement rapide et efficace, par contre comment tu limites à un style de paragraphe donné?

                                • 13. Re: Applying a same character style to different words inside a text
                                  Obi-wan Kenobi Adobe Community Professional
                                  var myTextFile = File(File(app.activeDocument.filePath + "/list.txt"));  
                                    
                                  if(myTextFile.exists) {  
                                      myTextFile.open();  
                                      var myWord = myTextFile.read();  
                                      myWord = myWord.split("\n");  
                                      myTextFile.close();  
                                      app.findGrepPreferences = app.changeGrepPreferences = null; 
                                      app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("Italics"); 
                                      while (myWord.length > 0 ) { 
                                          app.findGrepPreferences.findWhat = "\\b"+myWord.pop()+"\\b";
                                          app.findGrepPreferences.appliedParagraphStyle = "Blue";
                                          app.activeDocument.changeGrep(); 
                                          app.findGrepPreferences.appliedParagraphStyle = "Green";
                                          app.activeDocument.changeGrep(); 
                                      }
                                  }
                                  else alert (decodeURI(myTextFile) + " not found"); 
                                  

                                   

                                  My personal version, limited to 2 para styles, "Blue" and "Green"!

                                   

                                  Just place the "list" (saved in .txt) at the same level as the .indd file, change the char/para styles names, defining the targets [lines 12-13 duplicated].

                                   

                                  (^/) 

                                  1 person found this helpful
                                  • 14. Re: Applying a same character style to different words inside a text
                                    jane-e Adobe Community Professional

                                    https://forums.adobe.com/people/Obi-wan+Kenobi  wrote

                                    Sometimes, I really ask myself if people understand what they are told!

                                    quelquefois

                                    • 15. Re: Applying a same character style to different words inside a text
                                      Obi-wan Kenobi Adobe Community Professional

                                      "… C'est effectivement rapide et efficace …"

                                       

                                      Je prends ça pour une litote ! 

                                       

                                      (^/)

                                      • 16. Re: Applying a same character style to different words inside a text
                                        danieler36999951 Level 1

                                        Désolé maître Obi-Wan, but to me inDesign scripts are still a bit of a mystery.

                                        I went with Vinny's script because I could figure out how to run it without using too much code that I don't really know what means...

                                        • 17. Re: Applying a same character style to different words inside a text
                                          Obi-wan Kenobi Adobe Community Professional

                                          To Learn Something Maybe Time For You! 

                                           

                                          Imagine a 100-words list, a 100-para styles doc!

                                          … And the need to italicize these 100 words exluding paras where only 5 specific para styles are applied!!! 

                                           

                                          Just calculate: (100 - 5) * 100 = 9,500 code lines with FindChangeByList!!  Funny!

                                           

                                          I just prefer one work-minute and one click!

                                           

                                          Your list:

                                           

                                          Capture d’écran 2017-03-17 à 18.06.37.png

                                           

                                          Your ID file, before:

                                           

                                          Capture d’écran 2017-03-17 à 18.18.08.png

                                           

                                          Your ID file, after:

                                           

                                          Capture d’écran 2017-03-17 à 18.18.41.png

                                           

                                          The Script:

                                           

                                          /*
                                              0126_ApplyACharStyleToAWordsListWithExclusions_MichelAllio.jsx
                                              Script written by Michel Allio [2017/03/17]
                                          */
                                          
                                          
                                          app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Italics! …");
                                          
                                          
                                          function main()     
                                              { 
                                                  var myDoc = app.activeDocument,
                                                  myTextFile = File(File(myDoc.filePath + "/list.txt"));  
                                                    
                                                  if(myTextFile.exists) {
                                                      if (!myDoc.conditions.item("Target").isValid) myDoc.conditions.add ({name: "Target", indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor: [255,255,255]});
                                                      var myCondition1 = "Target";
                                                      if (!myDoc.conditions.item("Italics").isValid) myDoc.conditions.add ({name: "Italics", indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor: [200,200,150]});
                                                      var myCondition2 = "Italics";
                                                      myDoc.conditionalTextPreferences.showConditionIndicators = ConditionIndicatorMode.HIDE_INDICATORS;
                                                      
                                                      // Char Style Applied!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                      var myCharStyle = "Italics", // To Be Modified!
                                                      // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                      
                                                      // Para Styles Excluded!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                      myExcludedParaStyles = ["Blue", "Green"], // To Be Modified!
                                                      // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                      
                                                      E = myExcludedParaStyles.length;
                                                      while ( E-- ) {
                                                          app.findGrepPreferences = app.changeGrepPreferences = null;
                                                          app.findGrepPreferences.appliedParagraphStyle = myExcludedParaStyles[E];
                                                          app.changeGrepPreferences.appliedConditions = [myCondition1];
                                                          myDoc.changeGrep( );
                                                          }
                                                      myTextFile.open();  
                                                      var myWord = myTextFile.read();  
                                                      myWord = myWord.split("\n");  
                                                      myTextFile.close();  
                                                      app.findGrepPreferences = app.changeGrepPreferences = null;
                                                      app.findGrepPreferences.appliedConditions = [];
                                                      app.changeGrepPreferences.appliedCharacterStyle = myDoc.characterStyles.item(myCharStyle); 
                                                      while (myWord.length > 0) { 
                                                          app.findGrepPreferences.findWhat = "\\b"+myWord.pop()+"\\b";
                                                          app.changeGrepPreferences.appliedConditions = [myCondition2];
                                                          myDoc.changeGrep(); 
                                                      }
                                                      myDoc.conditions.item("Target").remove();
                                                      myDoc.conditionalTextPreferences.showConditionIndicators = ConditionIndicatorMode.SHOW_INDICATORS;
                                                      alert ("Done!\r\r(^/)  ;-)");
                                                  }
                                                  else alert (decodeURI(myTextFile) + " not found");
                                              }
                                          

                                           

                                          I only think it's a better way to fix this kind of question!

                                           

                                          (^/)