Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Calculation of Paragraph length(s) in a document

Return to Member Forum

  • Author
    Posts
    • #82964
      Bart Eenkhoorn
      Participant

      I would like to create an overview of paragraph lengths in a long document, or find paragraphs that exceed a certain number of words. Can this be done with a script? I have found this reference https://indisnip.wordpress.com/2010/12/28/quicktip-counting-text-using-everyitem/ but I need to look at paragraphs separately. It seems like such a script should be around somewhere.

      Thanks in advance for your help. Bart

    • #82965
      Ari Singer
      Member

      I don’t know if this helps, but when you select any paragraph and then look in the info panel, it shows you the amount of characters, words and lines. And if you select multiple paragraphs it shows you the amount of paragraphs selected as well.

      I don’t think this is what you’re looking for, but in the meanwhile this might help you.

    • #82966
      Bart Eenkhoorn
      Participant

      Yes Ari, I know about the info panel, but with a book containing 36 documents in total +500 pages, I would like a method to quickly identify the long paragraphs … I just read somewhere that intool’s style utilities can do this. Is this true? https://in-tools.com/products/plugins/style-utilities/

    • #82967
      Bart Eenkhoorn
      Participant

      Sorry, I meant that as a general question, can style utilities count paragraph length globally?

    • #82984
      Peter Kahrel
      Participant

      Maybe existing style utilities can determine paragraph length globally. As far as I can see, InTools’s style utility doesn’t, but a basic version is not difficult to script. The example below creates a text file Paragraph_count.txt on your desktop with the name of each document followed by a list of stories, each with a list of paragraph index and word count. The file is opened after script finishes.

      I said ‘basic’ because, well, it’s basic. It doesn’t do footnotes or tables, it includes stories on master pages, and you get just a raw count. And that’s the reason why general utilities tend not to include what you want: there are endless ways to customise the presentation of the data, so the script you’re after will typically be a custom job.

      (function () {
        
        var i, j;
        var report;
        var stories, par;
        var f;
        
        report = [];
        for (i = 0; i < app.documents.length; i++) {
          report.push (app.documents[i].name);
          stories = app.documents[i].stories.everyItem().getElements();
          for (j = 0; j < stories.length; j++) {
            report.push ('Story ' + stories[j].id);
            par = stories[j].paragraphs.everyItem().getElements();
            for (k = 0; k < par.length; k++) {
              report.push ('Par. ' + k + ':' + par[k].words.length);
            }
          }
        }
      
        f = File ('~/Desktop/Paragraph_count.txt');
        f.encoding = 'UTF-8';
        f.open('w');
        f.write(report.join('\r'));
        f.close();
        f.execute();
      }());
    • #82987
      Bart Eenkhoorn
      Participant

      Geweldig Peter,

      This is exactly what I was looking for. With a slight modification I can also use your script to count the characters:

      report.push (‘Par. ‘ + k + ‘:’ + par[k].characters.length);

      Here is part of that (word / character count) result (obviously, with many words, there are many characters as well)

      Par. 795: 0 1
      Par. 796: 12 71
      Par. 797: 254 1572
      Par. 798: 110 628
      Par. 799: 0 1
      Par. 800: 10 58
      Par. 801: 49 323

      Now let’s say, paragraph 797 contains more characters/words than our publication guidelines allow, is there any way in indesign to jump / go to paragraph 797 ?

      Thanks A lot for your generous help,

      Hartelijke groeten,

      Bart.

    • #82997
      Peter Kahrel
      Participant

      I’m trying to answer to this one but the reply doesn’t appear. . .

    • #82999
      Peter Kahrel
      Participant

      That one line worked, but a longer reply doesn’t.
      This thread clearly doesn’t like me any longer!

    • #83024
      Bart Eenkhoorn
      Participant

      Please try again, maybe I was blocking the thread inadvertently :-(

    • #83026
      Peter Kahrel
      Participant

      Still no luck. Now there’s a message saying “ERROR: Duplicate reply detected; it looks as though you’ve already said that!”
      Not sure what’s going on. Maybe David Blatner can fix this.

    • #83032
      Bart Eenkhoorn
      Participant

      I created a PART2 post, to continue this: https://creativepro.com/topic/part-2-calculation-of-paragraph-lengths-in-a-document
      Maybe we have more luck there.
      Bart

    • #83028
      Peter Kahrel
      Participant

      That report is not suitable directly to select a paragraph from. But something in-between that fancy approach (which is possible but requires more scripting) and nothing at all is the script below. Open the document, run the script, and enter the story id (in the report) and the paragraph index separated by a space, slash, whatever non-numeric, and press Enter or click OK.

       (function () {
        var parId = prompt ('Enter a story id followed by the paragraph index:', '');
        if (parId !== null) {
         // var parts = parId.split(/\D/);
          var par = app.documents[0].stories.itemByID(Number(parts[0])).paragraphs[parts[1]];
          app.windows[0].activePage = par.parentTextFrames[0].parentPage;
          par.select();
        }
      }());
    • #83831
      David Blatner
      Keymaster

      My apologies for the delay. I didn’t see this (Peter, in the future, if topics or replies don’t show up, please feel free to email me directly or contact us with the Contact Us form — link in the footer of this page)

      I have no idea why those replies didn’t show up. A forum mystery!

Viewing 12 reply threads
  • You must be logged in to reply to this topic.
Forum Ads