4 Replies Latest reply on Oct 5, 2009 4:00 PM by johnBking78

    Add: Part One, Part Two.......and so on

    johnBking78 Level 1

      I have a large document I want to add Part One, Part Two........... and so on to the beginning of each chapter title automatically, with a script, is this possible, and can someone (as I'm not so great a scripting) show me an example?

       

       

       

      Many thanks

        • 1. Re: Add: Part One, Part Two.......and so on
          [Jongware] Most Valuable Participant

          Hmmmm (thinking). It might boil down to this: search for your chapter titles (by style? I'll be assuming that!), insert 'part xx' before. Searching is no problem; inserting stuff is, because it messes up the 'found item' array. Let's start at the end, shall we. This code is not tested!

           

          var numerals = [ "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen" ]; (etc.)
          
          app.findTextPreferences = NothingEnum.nothing;
          app.findTextPreferences.appliedParagraphStyle = "ChapterTitle"; // [!! YOUR STYLE NAME HERE !!]
          
          allFoundItems = app.activeDocument.findText(true);
          // This returns the items in REVERSE ORDER :-)
          
          if (allFoundItems.length > numerals.length)
          {
            alert ("We're gonna need a bigger boat");
            exit(0);
          }
          
          for (occurrence=0; occurrence<allFoundItems.length; occurrence++)
          {
            allFoundItems[occurrence].insertionPoints[-1].contents = "Part "+numerals[allFoundItems.length-occurrence-1]+"\r";
          }
          

           

          The 'allFoundItems' array is in reverse order (as requested by findText), so the numbers should be inserted last-to-first. Let me know how that worked out

          • 2. Re: Add: Part One, Part Two.......and so on
            johnBking78 Level 1

            Hi [Jongware] and thanks for you help!!!

             

            It seams to add it after the Chapter header I want and ads a para brake? but its close and a start! if I can get it like this:

             

            Chapter one

            to:

            Part One Chapter One

            then:

            Part Two Chapter Two

             

            If you have any pointer that would be great! again thank you very much!!

            • 3. Re: Add: Part One, Part Two.......and so on
              [Jongware] Most Valuable Participant

              It works? Eh... sure it works.

               

              I had that at first but thought you might an extra paragraph inserted before. Just change the "\r" (a Return) at the end of the insertionPoint line to a single space " " (you can also change it to a tab: "\t", or something a bit longer).

              • 4. Re: Add: Part One, Part Two.......and so on
                johnBking78 Level 1

                Hi again and thanks for you help!

                 

                All I had to do was change this line:

                 

                 

                  allFoundItems[occurrence].insertionPoints[-1].contents = "Part "+numerals[allFoundItems.length-occurrence-1]+"\r";
                

                 

                 

                to:

                  allFoundItems[occurrence].insertionPoints[0].contents = "Part "+numerals[allFoundItems.length-occurrence-1]+" ";
                

                 

                 

                .insertionPoints[-1] I set to .insertionPoints[0] as it was adding it after, and as you said the last section to a space, then it worked a treat!

                 

                 

                Many thank!