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.
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();
Now ONE PAGE AT A TIME AND STARTING FROM THE BEGINING of the doc
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
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.
- Did a GREP search from beginning of paragraph till the colon.
- used a for loop to push the horizontalOffset number of each GREP search into an array.
- Used a for loop with if statement on the array to get the highest number in the array. That would be my "Longest Dialogue".
- Used geometricBounds() to find the text frame position.
- Found the position for the tab stop. tabStopPosition = longest dialogue position - text frame position.
- Added a little buffer to the tabStopPosition so that there would be seperation between the colon and the following text.
- Assigned tabStopPosition to a tabStop in the paragraph style associated with the text frame.
Thanks again for your help.
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.
@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: