13 Replies Latest reply on Oct 7, 2012 11:41 PM by Jump_Over

    Need Grep

    Steve_BDL

      Hi All,

       

      I am currently type-setting a dictionary and need to character style the keyword used in the example which follows the definition. of the entry. Following is an example of such:

       

      bukkett (buk-kett) n.m.

      pl.s. bukketti

      Ħafna fjuri marbutin flimkien b’xi żigarella. • F’Jum l-Omm Toni xtara bukkett fjuri lil ommu.

       

      Line 1: Paragraph style: Headwords using a grep style to give a character style (Headword) to the first word

      Line 2: Paragraph style: terms

      Line 3: Definition followed by example, seperated by a space, bullet and non-breaking space. Paragraph style: Text entry with a grep style styling the example with a character style (keyowrd in example).

       

      The above is all done. Now I need an additional grep style to find in the example the preceeding entry styled as Headword (in this case bukkett). Can this be done using grep or is it only possible using a script which I am hopeless in.

       

      I hope I was clear enough. If required I can make available for download a sample of the document including the current styles I'm using.

       

      Thank in advance

      Stephen

        • 1. Re: Need Grep
          Peter Spier Most Valuable Participant (Moderator)

          I think this is possible only using a script.

           

          And as an aside, you don't need a GREP style to do the bold on the first word of the first paragraph. You can use an ordinary Nested style, applied up to 1 ( to do the same thing, and it's more efficient. (that's not a typo, I mean up to one open parenthesis, so it will pick up multi-word entires as well).

          • 2. Re: Need Grep
            Steve_BDL Level 1

            Thanks Peter,

             

            After checking your suggestion, I just noticed that's exactly what I'm doing - using nested style. Thanks for pointing that out.

             

            Re scripting... that's out of my reach. I'm very ppor in Javascript and VB script.

             

            Tried looking into some of the examples coming with InDesign and cloese them quickly

            • 3. Re: Need Grep
              Peter Spier Most Valuable Participant (Moderator)

              You should ask for some help over in Scripting: InDesign Scripting

              1 person found this helpful
              • 4. Re: Need Grep
                Steve_BDL Level 1

                Thanks. Took your suggestion and posted in the Indesign scripting section.

                • 5. Re: Need Grep
                  Jump_Over Level 5

                  Hi,

                   

                  "preceeding entry" - you mean whole previous paragraph or some part of text before Headword?

                  • 6. Re: Need Grep
                    Steve_BDL Level 1

                    Hi,

                     

                    I need to find the HEADWORD (line 1, first word) in the example (line 3) and format it.

                     

                    You can download a sample file from here:

                    http://bdlbooks.com/files/Dictionary_sample.indd

                     

                    Thanks

                    • 7. Re: Need Grep
                      Jump_Over Level 5

                      Hi,

                       

                      Assuming:

                      Headword is a charStyle;

                      we are looking for same content in 2nd next paragraph;

                      we change format using charStyle (say "myTarget");

                      There is proper doc opened and active;

                      whole text is in linked textFrames;

                      1st textFrame is named: "myStoryFrame";

                      It could be like this:

                       

                      ______ copy this to ExtendScript Toolkit new empty file and run ______

                      ________________ or save it in your ScriptPanel folder _____________

                      ________________ and run from InDesign script panel ______________

                       

                      #target indesign

                       

                      try{myStory = app.activeDocument.textFrames.item("myStoryFrame").parentStory}

                      catch(e) {alert ("No story to search"); exit(); }

                      myDoc = app.activeDocument;

                      myHeadSt = myDoc.characterStyles.item("Headword");

                      myTargetSt = myDoc.characterStyles.item("myTarget");

                      app.findTextPreferences = NothingEnum.nothing;

                      app.changeTextPreferences = NothingEnum.nothing;

                      app.findTextPreferences.appliedCharacterStyle = myHeadSt;

                      app.changeTextPreferences.appliedCharacterStyle = myTargetSt;

                      myFound = myStory.findText();

                      for (k=0; k<myFound.length; k++) {

                           try {myCurrCont = myFound[k].words[0].contents}

                           catch (e) {alert ("Found text: " + myFound[k].contents + " is not a word"); exit(); }

                           myPara = myFound[k].paragraphs[0];

                           myNextPara = myStory.paragraphs.nextItem(myPara);

                           myTargPara = myStory.paragraphs.nextItem(myNextPara);

                           app.findTextPreferences = NothingEnum.nothing;

                           app.findTextPreferences.findWhat = myCurrCont;

                           myTargPara.changeText();

                           }

                       

                      alert("Finished; " + myFound.length + " changes done.");

                       

                      __________________________ END of script _________________________

                       

                       

                      hope it will help

                       

                      PS. I didn't check it with your example, cause it is a higher ID version. If you would export it to .idml

                      ==> I could open it.

                       

                      Message was edited by: Jump_Over

                      1 person found this helpful
                      • 8. Re: Need Grep
                        Steve_BDL Level 1

                        Hi,

                         

                        Thank you for your help.

                         

                        I have changed slightly your script as below to include both the 1st and the 2nd para . I need to make a condition to apply the change only if the text is italic.

                        Also I have re-uploaded the file as instructed.

                        bdlbooks.com/files/Dictionary_sample.idml

                         

                        try{myStory = app.activeDocument.textFrames.item("myStoryFrame").parentStory}

                        catch(e) {alert ("No story to search"); exit(); }

                        myDoc = app.activeDocument;

                        myHeadSt = myDoc.characterStyles.item("Headword");

                        myTargetSt = myDoc.characterStyles.item("keyword in example");

                        app.findTextPreferences = NothingEnum.nothing;

                        app.changeTextPreferences = NothingEnum.nothing;

                        app.findTextPreferences.appliedCharacterStyle = myHeadSt;

                        app.changeTextPreferences.appliedCharacterStyle = myTargetSt;

                        myFound = myStory.findText();

                        for (k=0; k<myFound.length; k++) {

                             try {myCurrCont = myFound[k].words[0].contents}

                             catch (e) {alert ("Found text: " + myFound[k].contents + " is not a word"); exit(); }

                             myPara = myFound[k].paragraphs[0];

                             myNextPara = myStory.paragraphs.nextItem(myPara);

                             myTargPara = myStory.paragraphs.nextItem(myNextPara);

                             app.findTextPreferences = NothingEnum.nothing;

                             app.findTextPreferences.findWhat = myCurrCont;

                             myNextPara.changeText();        

                             myTargPara.changeText();

                             }

                         

                        alert("Finished; " + myFound.length + " changes done.");

                        • 9. Re: Need Grep
                          Jump_Over Level 5

                          Hi,

                           

                          This "italic" condition is because italic could be set manually?

                          If "italic" comes from charStyle, you have it always in TargPara and never in NextPara.

                           

                          However...

                          if your goal is to include this condition, add the line:

                          app.findTextPreferences.fontStyle = "Italic";

                          after

                          app.findTextPreferences.findWhat = myCurrCont;

                           

                          you can also change:

                          myNextPara.changeText();        

                          myTargPara.changeText();

                          with:

                          myStory.paragraphs.itemByRange(myNextPara, myTargPara).texts[0].changeText();

                           

                          to keep it in one step.

                           

                          rgds

                          1 person found this helpful
                          • 10. Re: Need Grep
                            Steve_BDL Level 1

                            Thank you.

                             

                            I tried this script on the sample file and most of the instances are correct. I still have some issues like when the word contain glyphs but that's not to worry. I will still be going through the whole document checking it out.

                             

                            My major problem is that when I run the script on the main file I get a notice that say "Found text:   is not a word". It does not give me what text it found and there seem to be a space. Can I get the page number or make it highlight and set focus on this instance so that I can correct any such problems?

                             

                            Thank in advance.

                            • 11. Re: Need Grep
                              Jump_Over Level 5

                              Hi,

                              In case of this alert, some text with charStyle "Headword" set - has no contents

                              (some kind of space, specialCharacter, etc)

                               

                              To make it shown - include

                                   myFound[k].showText();

                              before

                                   exit();

                               

                               

                              Yoy can replace

                                   exit()

                              with

                                   continue;

                               

                              also, to keep script working instead of exit job.

                               

                              rgds

                               

                              Message was edited by: Jump_Over

                              1 person found this helpful
                              • 12. Re: Need Grep
                                Steve_BDL Level 1

                                Thank you to all of you who helped me out in this. Really impressed with the high qaulity assistance available. It took quite a while to complete, over 4 hours, then I left and let the computer on. I'm here today and everything looks good.

                                 

                                This saved me alot of manual formatting.

                                 

                                Thank you once more.


                                Regards

                                Stephen

                                • 13. Re: Need Grep
                                  Jump_Over Level 5

                                  Yrw

                                   

                                  If something was "helpful" or "correct" - check it pls

                                  rgds