3 Replies Latest reply on May 17, 2010 12:54 PM by BRUNNEBA

    Java script automate paragraph with bullets.

    BRUNNEBA Level 1

      I have a text frame that has data with a paragraph style that looks like this...

       

       

      • First Bullet italics style called bullet1:
        • Sub bullet is style called subbullet1.
        • Sub bullet 2 is style called subbullet1
      • Second Bullet italics style called bullet1:
        • Sub bullet is style called subbullet1.
        • Sub bullet 2 is style called subbullet1

      There are also special spacing and indents on the styles, but basically,

       

      I want to replace all of this text with new bullets and sub bullets for over 50 pages.  Is there a script that will handle this?

       

      I have 50 seperate text files with the text for each page that is generated automatically, but there are no styles or indents.

       

      So, in pseudocode, I want to...

       

      go to page 1 --> place p1.txt into text frame at [x,y]  (replacing what is already in the text frame)

      go to page 2 --> place p2.txt into text frame at [x,y]...

      go to page 50 --> place p50.txt into text frame at [x,y]

       

      where x and y are always the same, using the top left point.

        • 1. Re: Java script automate paragraph with bullets.
          [Jongware] Most Valuable Participant

          Select one of your text frames and run the quick script from the end of my post -- would it be a starting point for what you need?

           

          The script reads a plain text file and replaces the current selection contents (a TextFrame) with this text. Since it is a plain text file, all formatting that gets applied is simply the formatting of the first paragraph in the original text frame, and if the frame is empty, the default paragraph style gets applied.

           

          If you need some lines to have a certain style and others another style, you'll have to find a way to express that in code.

           

          Also: a script does not really have a way to "place text at [x,y]". If there is a way to uniquely identify the frame in which to place the text, the script can use that. A unique identifier could be a script label, or perhaps it's even as simple as "but there is only one frame per page". If there are, or might be, more than a single frame per page, the script has to loop over all objects and test for each if the point [x,y] is inside one of them. And you'll need a Plan B in case there is more than one frame at that position.

           

          That's the hard part. Surprisingly, looping over 50 files for 50 pages is the easy part!

           

           

          filename = "p1.txt";
          myFileObj = new File(filename);
          if (myFileObj.open("r"))
          {
               theText = myFileObj.read();
               myFileObj.close();
               app.selection[0].contents = theText;
          } else
          {
               alert ("Unable to open file "+filename);
          }
           
          
          1 person found this helpful
          • 2. Re: Java script automate paragraph with bullets.
            BRUNNEBA Level 1

            Yes, this placed the text in the text frame I was working with, but I do need it to apply a different style on nearly each line.

             

            I used to run a really long script that worked through the all frames one at a time by moving the cursor to the end of each line, then editing/replacing text, line by line.  That was in Pagemaker 7.   Here is what my old script in PM7 used to look like....

             

            page 1
            select(-3,4)
            textedit
            textcursor -story, 2
            textcursor +para
            textcursor +char, 2
            textselect +para
            textselect -char
            textenter "This line adds text the first bullet "
            textcursor +para, 1
            textcursor +char, 2
            textselect +para
            textselect -char
            textenter "This line adds text for the next bullet"

            page 2

            select(-3,4)
            textedit
            textcursor -story, 2
            textcursor +para
            textcursor +char, 2
            textselect +para
            textselect -char
            textenter "This line adds text the first bullet "

            ....... to page 50.

             

            This way, the paragraph style didn't change.  So, I almost would rather do it that way, since I already have a program that writes out the text file.  It seems like I just need to add some code for handling the cursor, but is that possible in CS4?  

            • 3. Re: Java script automate paragraph with bullets.
              BRUNNEBA Level 1
              function(){return A.apply(null,[this].concat($A(arguments)))}

              [Jongware] wrote:

               

              Select one of your text frames and run the quick script from the end of my post -- would it be a starting point for what you need?

               

              The script reads a plain text file and replaces the current selection contents (a TextFrame) with this text. Since it is a plain text file, all formatting that gets applied is simply the formatting of the first paragraph in the original text frame, and if the frame is empty, the default paragraph style gets applied.

               

               

               

               

               
              

               

               

              I have tried to apply custom paragraph styles to different lines in the text, but CS4 doesn't seem to let me do that after running this script.  Once this script runs, I can't seem to apply multiple styles.    Then I tried removing all custom paragraph styles first and then running the script to dump plain text in the frame.  After that, it will let me make those changes to multiple lines, but how can I create a script to do that, when the text for each bullet may change from page to page.  It's almost like I need a marker in my text file to indicate the start and end of a bullet vs. title etc.  Do you have any further suggestions on how I would have some lines with one style and other lines with another style?    What if I were using an XML file instead of .txt?  Would that make any difference?