6 Replies Latest reply on Feb 2, 2012 6:06 AM by கற்பனை (Imagine)

    get text from Paragraph?

    கற்பனை (Imagine) Level 3

      Hi All,

       

      How to extract the perticular text object from the single paragraph.  I searched in the forums and get the paragraph.texts.itemByRange() methods,  but i don't know how to use this method to get the perticular text and I want to remove the text from the Paragraph.

       

      I will appreciate for any helps...

       

      Regards,

      Imagine

        • 1. Re: get text from Paragraph?
          [Jongware] Most Valuable Participant

          How are you deciding what particular text to remove?

           

          Your sample might not work because you are using 'paragraph.texts', which is kind of reversing the normal use of 'text'. "Text" is the superclass, and Paragraph is derived from that -- targeting "texts" from within a paragraph returns just that same paragraph again.

          You are probably looking for characters instead:

           

          targetParagraph = app.activeDocument.stories[0].paragraphs[0];
          randomStart = Math.floor(Math.random()*targetParagraph.characters.length);
          randomLength = Math.floor(Math.random()* (targetParagraph.characters.length-randomStart) );
          anyRange = targetParagraph.characters.itemByRange (randomStart, randomStart+randomLength);
          alert ('Press OK to delete "'+anyRange.contents+'"!');
          anyRange.remove();
          
          1 person found this helpful
          • 2. Re: get text from Paragraph?
            கற்பனை (Imagine) Level 3

            [Jongware] wrote:

             

            How are you deciding what particular text to remove?

             

            In that perticular paragraphs has the certain standard markup text, I want to remove that text and place a range of paragraphs on that position.  (app.selection[0] Paragraphs).  is it possible in few lines of script?

            • 3. Re: get text from Paragraph?
              [Jongware] Most Valuable Participant

              Uh. Yeah sure, but without a bit more detail it's hard to guess how many lines of script it needs. Why does the number of lines matter?

              • 4. Re: get text from Paragraph?
                கற்பனை (Imagine) Level 3

                [Jongware] wrote:

                 

                Why does the number of lines matter?

                 

                few lines of code will always look like neat coding.  I'm doing the automation like to fetching the user selected ranges of text and move that into a box markup Text area,  finally to remove that markup and apply a style on that text part. is it right approach or any better way?

                • 5. Re: get text from Paragraph?
                  [Jongware] Most Valuable Participant

                  Sorry, that doesn't make it more clear.

                   

                  1. itemByRange is only useful when you have the start and end of the range as numbers. What where you planning to do? Ask in a dialog box from where to where to remove? The "user selected ranges" of text is just a selection, and you can manipulate that immediately. There is no reason to convert it to a format usable for itemByRange first.

                   

                  2. At this point in your learning stage, shouldn't you be concentrating on Getting The **** Thing To Work, rather than focusing on writing elegant, maintainable, short but not obfuscated code? All of those have no meaning if your script does not run.