• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
10

I wanna order my questions and answers sort to the “key” paragraph style, from smallest to largest

Participant ,
Dec 26, 2023 Dec 26, 2023

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. 

TOPICS
Scripting

Views

731

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Dec 29, 2023 Dec 29, 2023

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
...

Votes

Translate

Translate
Community Expert , Dec 29, 2023 Dec 29, 2023

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

...

Votes

Translate

Translate
Participant ,
Dec 30, 2023 Dec 30, 2023

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".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 30, 2023 Dec 30, 2023

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 30, 2023 Dec 30, 2023

Copy link to clipboard

Copied

Ah, but you never said, and your sample didn't show that!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 30, 2023 Dec 30, 2023

Copy link to clipboard

Copied

Sorry @Peter Kahrel 
you are absolutely right... 

You were an inspiration in the work of the script. Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 30, 2023 Dec 30, 2023

Copy link to clipboard

Copied

LATEST

@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".

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines