6 Replies Latest reply on Oct 7, 2012 11:22 PM by Steve_BDL

    Script required for styling

    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 nested 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.

       

      I need a script to find in the example the preceeding entry styled as Headword (in this case bukkett). I am very poor in Javascript and VBscript.

       

      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: Script required for styling
          [Jongware] Most Valuable Participant

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

           

          Please do. It's ever so easy to find out with *actual* data. What version of InDesign are you using, by the way?

          • 3. Re: Script required for styling
            -hans- Level 4

            Hi,

             

            was grumbling for a clever solution, but didn't find one ;-)

             

            No errorhandling applied ...

             

             

            var myDoc = app.activeDocument;
            var allStories =  myDoc.stories;
            s = allStories.length;
            for(var i = 0; i < s;i ++){
            currStory =     allStories[i];
            var storyParagraphs = currStory.paragraphs;
            p = storyParagraphs.length;
            for(var j = 0; j < p;j++){
            var currPara = storyParagraphs[j];
            var paraName = currPara.appliedParagraphStyle.name
            switch(paraName){
            case  'Headwords'  : 
            app.findTextPreferences = NothingEnum.nothing;   
            app.findTextPreferences.appliedCharacterStyle = 'Headword';   
            var Res = currPara.findText();
            var resCont = Res[0].texts[0].contents; break;
            case 'Text entry' : 
            app.findTextPreferences = NothingEnum.nothing;   
            app.changeTextPreferences = NothingEnum.nothing;
            app.findTextPreferences.findWhat = resCont;
            app.changeTextPreferences.appliedCharacterStyle = 'keyword in example';
            currPara.changeText(); break;
            default : break;
                    }
            }
                }
            app.findTextPreferences = NothingEnum.nothing;   
            app.changeTextPreferences = NothingEnum.nothing;
            

             

            Hans-Gerd Claßen

            • 4. Re: Script required for styling
              Steve_BDL Level 1

              Many thanks for your script.

               

              I have re-uploaded the file here, this time in idml format.

              http://www.bdlbooks.com/files/Dictionary_sample.idml

               

              I need to trim the findText from spaces for it to work better.

              • 5. Re: Script required for styling
                -hans- Level 4

                Hi,

                 

                your nested style in Headwords = 'headword over 1 words' includes the space behind the first word. Guess it should be till 1 words.

                As I work on a German version it's called 'über' und 'bis'

                 

                Hans-Gerd Claßen

                • 6. Re: Script required for styling
                  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