Copy link to clipboard
Copied
Hi,
I have a document with hundreds of questions and answers. I want to order my questions and answers sort to the “key” paragraph style, from smallest to largest. There can be any order for those with the same number.
I have attached the indesign copy document. Thanks advice.
Try this one.
Select one of the text frames that your exam story sits in, then run the script.
(function () {
var i, par, temp;
var blocks = [];
var story = app.selection[0].parentStory;
if (story.characters[-1].contents != '\r') {
story.insertionPoints[-1].contents = '\r';
}
par = story.paragraphs.everyItem().getElements();
for (i = 0; i < par.length-6; i = i + 7) {
blocks.push ({
key: Number(par[i+5].contents.match(/\d+/)[0]),
text: story.paragraphs.it
...
Hi @Peter Kahrel, thank you for this, that is a very efficient approach and helped me a lot.
With your help I have updated my script. It will not be as fast as yours because it is careful about which paragraphs to move (eg. it won't damage non-question paragraphs in the same story if they occur before or after the questions — see screen shot below), but it will be faster than my first attempt. On my computer here, using your demo document but with 1000 questions, and the "safe" paragraphs befo
...Copy link to clipboard
Copied
Hi @m1b ,
Definitely this script is very fast. He ordered 400 questions in 15 seconds. Thank you very much.
I found another solution as follows...
I created a temporary "key para style". I solved every question. I used Marc Autret's "smart sort" script. I sorted all the questions. Then I removed a Temporary "key para style".
Copy link to clipboard
Copied
Hi @Peter Kahrel,
It works very fast, (sample file I sent) but it gives an error when the number of paragraphs is different. Thank you...
Copy link to clipboard
Copied
Ah, but you never said, and your sample didn't show that!
Copy link to clipboard
Copied
Sorry @Peter Kahrel
you are absolutely right...
You were an inspiration in the work of the script. Thanks.
Copy link to clipboard
Copied
@uniq1, from your file, I can see that you work on a PC - would you be interested in trying my tool?
I can give you access to the full version for some time.
In return - one condition and one request:
Condition - you'll supply me with as many requests / challenges as you can think of. For example - preflight / validation if there are always 3x answers, or "key" paragraph / value is present and populated, or "answer" is present and not empty, etc. - whatever will make your life easier.
Request - you'll give me permision to use and publish "case study" based on your file(s) - even if they are filled with "lorem ipsum".