3 Replies Latest reply on Sep 6, 2013 5:52 AM by AndrewMathieu

    Not count parargraphs with no printable characters


      This small script below returns the index number of a starting paragraph and the ending paragraph selected within the active Story.  How do we not count paragraphs with no printable characters?


      Ultimately we are trying to incorporate into a spacing script, were the user can select paragraphs in one story to adjust leading, and then the script will calculate the matching paragraph in the other story, adjusting it as well.  We are using insertionPoints and paragraphs as reference points.


      myTF = app.selection[0].parentTextFrames[0];

      myText = app.selection[0];

      startParaIndex = myText.parentStory.insertionPoints.itemByRange (myTF.insertionPoints[0].index, myText.index).paragraphs.length;

      endParaIndex = myText.parentStiry.insertionPoints.itemByRange (myTF.insertionPoints[-1].index, myText.index).paragraphs.length;

      alert("Start : " + startParaIndex + "\n End : " + endParaIndex);



        • 1. Re: Not count parargraphs with no printable characters
          Peter Spier Most Valuable Participant (Moderator)

          Moved to InDesign Scripting

          • 2. Re: Not count parargraphs with no printable characters
            csm_phil Level 4

            Hi Andrew Mathieu,


            I am not clear what you expect? May be you try the below JS line it will help you. Also find the screen shot.





            var mySelection = app.selection[0];
            alert("Printable Characters :" +mySelection.words.length+"\nTotal Paragraphs Count : "+mySelection.paragraphs.length);




            • 3. Re: Not count parargraphs with no printable characters
              AndrewMathieu Level 1

              Hi Phil,


              Sorry I should of been more specific.  What we are really trying to achieve, is that we have a script that changes leading based on user selection with mouse and input into a dialog for size.  But currently the user can only change leading for textframe one at a time.....We have two textframes side by side english, french.


              We are trying to find a way to do both simultaneously.  Unfortunately you cant highlight and select over into two seperate textframes. Hence this script.  We thought by identifying the index number of the starting and ending paragraphs we could achieve this.  But we realised that paragraphs with no printable characters is also being counted which causes problems.


              But currently non printable characters are being counted even in empty paragraphs.  This ultimately results in different index locations of start and ending paragraphs for both textframes.


              Maybe you know of a better way to achieve simultaneous leading of two textframes?


              Here is a short test sample we've been using giving us exact location of non printable characters.


              function cleanContent(str)


                  str = StringUtils.replaceAll(str,"\r","");

                  str = StringUtils.replaceAll(str,"\n","");

                  str = StringUtils.removeExtraSpaces(str,true,true,true);


                  return str;








                  var t = app.selection[0].paragraphs[0].contents;



                  alert (cleanContent(t));


              catch (e)