5 Replies Latest reply on Aug 6, 2013 12:29 AM by Laubender

    Changing tabs value in paragraph style based on longest word

    tusharde Level 1


      I am writing a javascript that wil find all dialogue in a text frame, indent it and bold it. I have managed to figure out with GREP how to find and bold the dialogue, but i can't figure out a way to dynamically calculate what the longest needed tab stop to align the left edge of the dialogue. Picture attached to illustrate what i am looking for. Any help would be appreciated.


      Screen Shot 2013-08-05 at 7.16.18 AM.jpg

        • 1. Re: Changing tabs value in paragraph style based on longest word
          Dave Saunders Level 4

          It's not clear what's causing you dificulty. Are you aware of the horizontalOffset property of text? With that, you can measure the length of the dialog prefixes in the paragraphs of interest and then use the largest value plus some buffer to set your paragraph -- you speak of tabs, but it seems to me that the left marging and first line inset are all you really need to set.



          • 2. Re: Changing tabs value in paragraph style based on longest word
            Trevorׅ Adobe Community Professional

            Here's a more detailed flow of Dave's method (I think):


            If you have indent to here tabs get rid of them using textFind .. findWhat = "^i"; changeTo = ""; myDoc.changeText();




            Do grep seach on each paragraph ......findWhat = "^[^:]:\\s"; to find the colons

            make an array of the endHorizontalOffset values of myFinds[i].insetertionPoints[-1].endHorizontalOffset;


            If you are using paragraph composer you are going to have to allow for changes in the layout so if you can use the single line composer it's a lot more simple.


            Now set the indents (first line indent 0 otherlines to value x)


            To calculate value x see which paragraph is the most inserted i.e. which had the biggest endHorizontalOffset value on the page and set the indents of all the paragraphs on the page to this biggest value.


            CHECK that that paragraphs still starts on the page. If yes continue with the next page BUT be careful not to change the indent value of the first paragraph of that page if it starts on the page before unless it only has one line on the page before then you need to change the value of the second+ line indent of that paragraph.


            If the paragraph is bumped off to the next page then set the pages paragraph indents to the 2nd largest indent value and do the same check and so on.


            One major snag, what to do if when one sets to the largest indent value the paragraph gets bumped off so one sets the paragraph to the second largest value and then the bigger paragraph now comes back on the page?


            Probably best to put in a frame or column break.


            In short - not so easy


            If you can put that together or if some saint on the forum is prepared to do it for you even better if not then send me or Dave a private mail for a quote. Or Send me a mail to trevor at creative-scritps dot com.



            Best of luck



            • 3. Re: Changing tabs value in paragraph style based on longest word
              tusharde Level 1

              Thanks for your help, Dave. I am new to indesign scripting. I wasn't aware of the horizontalOffset property of text. That was a great tip. Appreciate it.


              Here's what i ended up doing.


              1. Did a GREP search from beginning of paragraph till the colon.
              2. used a for loop to push the horizontalOffset number of  each GREP search into an array.
              3. Used a for loop with if statement on the array to get the highest number in the array. That would be my "Longest Dialogue".
              4. Used geometricBounds() to find the text frame position.
              5. Found the position for the tab stop. tabStopPosition =  longest dialogue position - text frame position.
              6. Added a little buffer to the tabStopPosition so that there would be seperation between the colon and the following text.
              7. Assigned tabStopPosition to a tabStop in the paragraph style associated with the text frame.



              Thanks again for your help.

              • 4. Re: Changing tabs value in paragraph style based on longest word
                tusharde Level 1

                Thanks for your response Trevor. I saw Dave's email, messed around a bit, and found a solution that currently works. Not sure if it's the same thing you were talking about. I appreciate you taking the time to help.

                • 5. Re: Changing tabs value in paragraph style based on longest word
                  Laubender Adobe Community Professional & MVP

                  @tusharde – Just one thing to add:


                  The value of "horizontalOffset" is in the measurement unit the user did apply to the horizontal ruler. That also means, you cannot rely on the value, if you rotated your text frame.


                  Here an example for the values of "horizontalOffset" of the insertion point before "Text" and after "Text". Not rotated text frame vs. rotated one (red lines) and the values you are looking for (green lines):




                  The value of horizontalOffset is also tied to the baseline of the insertionPoint you are using for the meassurement. In rotated text frames, baseline shift will change the value, too: