5 Replies Latest reply on Aug 3, 2009 8:27 AM by Dave Saunders

    Display paragraph content

    RockScript Level 1

      Hi ,

       

      i can able to display the first paragraph and last paragraph content in the page (if i have only one textframe in the page). my problem is if

       

      i have more than one text frame that means if i have 3 text frame i want to display the first textFrame first paragraph content and third textframe

       

      last paragraph content. i strugle with this onle could anyone help me.

        • 1. Re: Display paragraph content
          Dave Saunders Level 4

          Are these text frames threaded or independent? I'm guessing threaded because otherwise how to know which is first and which last.

           

          If they're threaded, I'd imagine they're part of some kind of main story, so it should be possible to just walk through the story gathering the information you need.

           

          What does your current script look like? That will help us give advice.

           

          Dave

          • 2. Re: Display paragraph content
            RockScript Level 1

            Hi Dave,

             

            Thanks for your response . That is threaded frame only. First paragraph means starting line of the textFrame content. last paragraph means ending line

             

            of the paragraph content. Here i attached the code . that i can able to use only one textFrame in the textframe. but if i have more than one

             

            textframe firsttext frame content and last textframe content i want to display.

             

             

            Thanks in advance

             

             

             

            var myDoc = app.activeDocument;
            var myTextFrame = app.selection[0];
            var firstPar = myTextFrame.paragraphs[0];
            var  firstChar = myTextFrame.characters[0].contents;
            var visibleParagraphContents = myTextFrame.paragraphs[0].contents.substring (firstChar.index - firstPar.index);

             

            alert(app.selection[0].constructor.name)
            alert ("First Paragraph content   :"+"\n" + visibleParagraphContents);
            alert ( "Last Paragraph content   : "  + "\n"+ myTextFrame.paragraphs.lastItem().contents);

            • 3. Re: Display paragraph content
              [Jongware] Most Valuable Participant

              Dave: see http://forums.adobe.com/message/2140218#2140218 for the preliminary movements. I'm surprised to see Rock is struggling with my simple three-step plan...

              • 4. Re: Display paragraph content
                Dave Saunders Level 4

                Rock's current script starts with identifying the text frame of interest by using the selection. That's fine for testing concepts but it's not going to get you very far in a production script.

                 

                Your three-step approach assumes that the "last" frame on the page is lower down the page than the others, but it could be three side-by-side identical height frames.

                 

                Given that they're threaded, I'd use that to do this job. Presumably, the ultimate goal is to put the content of these paragraphs somewhere useful (such as a running head -- although you could use text variables for that).

                 

                Here's an approach: it assumes that none of the frames of the story are in groups or inline.

                //DESCRIPTION: Get Contents of First & Last Paras on Pages of Story
                
                (function() {
                     if (app.documents.length > 0 &&
                          app.selection.length > 0 &&
                               app.selection[0].hasOwnProperty("parentStory")) {
                          var myParas = getHeadsTails(app.selection[0].parentStory);
                          for (var j = 0; myParas.length > j; j++) {
                               alert(myParas[j].page.name + "\nhead: " + myParas[j].head + "tail: " + myParas[j].tail);
                          }
                     }
                     function getHeadsTails(story) {
                          var paras = new Array();
                          var frames = story.textContainers;
                          var pageRecord = new Object();
                          pageRecord.head = frames[0].paragraphs[0].contents;
                          curPage = frames[0].parent; // assumes frames are loose on page
                          pageRecord.page = curPage;
                          for (var j = 0; frames.length > j; j++) {
                               if (frames[j].parent != curPage) {
                                    pageRecord.tail = frames[j-1].paragraphs[-1].contents;
                                    paras.push(pageRecord);
                                    var pageRecord = new Object();
                                    pageRecord.head = frames[j].paragraphs[0].contents;
                                    curPage = frames[j].parent;
                                    pageRecord.page = curPage;
                               }
                          }
                          pageRecord.tail = frames[j-1].paragraphs[-1].contents;
                          paras.push(pageRecord);
                          return paras
                     }
                }())
                

                To make this script useful, you'd need to do something more intelligent with the values returned by getHeadTails. It might be smarter for that function to return paragraph references rather than the contents of the paragraphs.

                 

                Dave

                • 5. Re: Display paragraph content
                  RockScript Level 1

                  Thank you very much Dave