Sorting alphabetically text blocks
Hi there,
While still a begginer with scripting, I'm looking forward to learn some more about scripting and ID.
For the time being, I'm having a time-consuming routine that I would like to change thanks to scripts.
Here's where I need help:
- I need to sort alphabetically text blocks based on a Title (Paraph.style Title 1, for instance, the Level 1, if I may say). I cannot use the well known scripts sort-alpha or any I've found on the web, like the one included in ID, because my text blocks include sub-paragraphs, with various para.styles. When using them, the sub-paragraphs would be put out of their sections. To understand the need, just think about translating texts that are properly listed alphabetically in english. Obviously they're not listed properly anymore after the translation.
How would you tackle the task ?
apart from the Toc, there 's no real hierarchy level in paraph styles, as far I know. Ther's no way, so far, to manipulate groups of mixed paraph.styles (except by using text frames… you see me coming^^).
Here's an example:
Before (meaning, after translation)
CCCC (Style: Title 1)
Title 3 level 2
text 5
text 6
BBBBB (Style: Title 1)
Title 2 level 2
text 3
text 4
AAAA (Style: Title 1 level 1)
Title 1 level 2
text 1
text 2
After sorting them properly:
AAAA (Style: Title 1 level 1)
Title 1 level 2
text 1
text 2
BBBBB (Style: Title 1)
Title 2 level 2
text 3
text 4
CCCC (Style: Title 1)
Title 3 level 2
text 5
text 6
Idealy, I would select my text blocks then run the script, very similar to sort-alpha scripts we use so far.
The first line of my selection would be in the style used for putting into order the texts
After thinking about it, I believe we could probably break down the task into smaller and simpler sub-scripts, like so :
1- Upon selection, detect groups of texts (starting from the 1st letter of Title 1 paraph.style, up to the next one - if any). Record position of 1st letter of selection.
- cut/ paste into new text frames the various group texts, as they are (meaning, keeping the current formatting)
2- - read the first letter of the text frames and sorting alpha the text frames
- Merge the frames
3- Copy/ paste the text from the merged text frame at the initial recorded position
- Delete text frame
What do you think ?
