17 Replies Latest reply on Jun 12, 2013 7:03 PM by ProtonAus

    How do I number paragraphs in reverse order high to low?

    ProtonAus

      How do I number paragraphs in reverse order high to low, preferably with the LAST paragraph No. 1?

       

      Ideally would like to be able to add paragraphs at the top (start) and have these numbered sequentially e.g. if there were ten paras numbered 10 (start) to 1 (end), would like the next para at start to be numbered 11 and so on.  For a revision log - latest at top.

        • 1. Re: How do I number paragraphs in reverse order high to low?
          Eugene Tyson Adobe Community Professional & MVP

          I can't remember where I got this from - so apologies for no credit

           

          I've only be able to this with a script

           

          if (app.selection.length == 0 || !(app.selection[0] instanceof InsertionPoint))

          {

          alert ("Please place the text cursor in the first paragraph with a numbered list…");

          exit(0);

          }

          firstp = app.selection[0].paragraphs[0];

          if (firstp == null || firstp.bulletsAndNumberingListType != ListType.NUMBERED_LIST)

          {

          alert ("That's not a numbered list…");

          exit(0);

          }

          lastp = firstp;

          while (lastp.paragraphs.nextItem(lastp) != null && lastp.paragraphs.nextItem(lastp).bulletsAndNumberingListType == ListType.NUMBERED_LIST)

          lastp = lastp.paragraphs.nextItem(lastp);

           

          // Reached the end of this numbered list. So…

          var count = firstp.numberingResultNumber;

          do

          {

          lastp.properties = ({numberingContinue:false, numberingStartAt:count});

          count++;

          if (lastp == firstp)

          break;

          lastp = lastp.paragraphs.previousItem(lastp);

          } while (1);

          • 2. Re: How do I number paragraphs in reverse order high to low?
            [Jongware] Most Valuable Participant

            Eugene Tyson wrote:

             

            I can't remember where I got this from - so apologies for no credit

             

            That would be http://indesignsecrets.com/topic/numbered-list-in-reverse. It's not 'automatic', i.e., every time you change the list you have to re-run the script.

            • 3. Re: How do I number paragraphs in reverse order high to low?
              Eugene Tyson Adobe Community Professional & MVP

              Don't even remember reading that forum post

              • 4. Re: How do I number paragraphs in reverse order high to low?
                Peter Spier Most Valuable Participant (Moderator)

                So Theun, what's up with the new avatar?

                 

                Have we insulted you?

                • 5. Re: How do I number paragraphs in reverse order high to low?
                  TᴀW Adobe Community Professional & MVP

                  Lol. I was wondering about that too.

                   

                  Ariel

                  • 6. Re: How do I number paragraphs in reverse order high to low?
                    [Jongware] Most Valuable Participant

                    Peter Spier wrote:

                     

                    So Theun, what's up with the new avatar?

                     

                    My previous new avatar got rejected by a moderator who was afraid it would lead people to think I am an Adobe employee:

                     

                    id-classic-sml.png

                     

                    (ironically, as it is meant to express a counter-Adobe stance against CC). So I overlaid it with a subliminal layer, only visible when wearing sunglasses.

                    • 7. Re: How do I number paragraphs in reverse order high to low?
                      Peter Spier Most Valuable Participant (Moderator)

                      Anyone who's read your posts lately knows you're not an Adobe employee.

                       

                      But I do see how one or another mod might have had a problem. I can kick it back up the food chain and see what the admin says, if you like. I think I'd be more worried about Coca Cola coming after you, myself.

                      • 8. Re: How do I number paragraphs in reverse order high to low?
                        Larry G. Schneider Adobe Community Professional & MVP

                        So as not to be blinded by the incandescent Adobe light?

                        • 9. Re: How do I number paragraphs in reverse order high to low?
                          [Jongware] Most Valuable Participant

                          Larry G. Schneider wrote:

                           

                          So as not to be blinded by the incandescent Adobe light?

                           

                          Larry, it's a reference to John Carpenter's 1988 masterpiece "They Live". Never seen that'un?

                          • 10. Re: How do I number paragraphs in reverse order high to low?
                            Larry G. Schneider Adobe Community Professional & MVP

                            Nope, I'm not much of a movie fan but it could also be from "1984".

                             

                            Just Googled it and the parallels are too close. Where do I get may sunglasses?

                            • 11. Re: How do I number paragraphs in reverse order high to low?
                              ProtonAus Level 1

                              Thank you very much Jongware.

                               

                              This works well ... up to a point ... but stops on the first non-numbered paragraph encountered (i.e. in my case a date heading).

                               

                              I think I can see dimly how to modify the script to skip non-numbered paras but I am new to scripts so would appreciate some help if it's not too much trouble.

                               

                              My aim is to have a stack of numbered paragraphs starting from 1 at the end proceeding to the highest number at top (start) with some headings and unnumbered explanatory paras interspersed, so I think if the script was able to jump over unnumbered paras and continue on it would work correctly?

                               

                              Thanks also to Eugene Tyson for pointing to this.

                               

                              I don't understand the other posts (also got a stack of unwanted emails!).

                              • 12. Re: How do I number paragraphs in reverse order high to low?
                                Laubender Adobe Community Professional & MVP

                                @ProtonAus – I took one of the original concepts in Jongware's script (setting a numbered paragraph to "Numbering Continue = false", renumbering the start to a declining number counter) and rewrote it so unnumbered paragraphs in between will not affect the renumbering of the numbered paragraphs.

                                 

                                Requirements:
                                1. Select the WHOLE range of text you want to renumber in reverse (including all unnumbered paragraphs)
                                2. Numbered paragraphs (no paragraph styles necessary)

                                 

                                Side effect:
                                Numbered paragraph styles are overwritten (+ sign will indicate that)

                                 

                                What it does NOT do:
                                Reverse number paragraphs in tables

                                 

                                //ReverseNumberingOfNumberedParagraphs_TEXTRANGE_SELECTION.jsx
                                //Uwe Laubender
                                
                                //Based on a script by Jongware
                                //http://indesignsecrets.com/topic/numbered-list-in-reverse#reply-31983
                                
                                //Also discussed here:
                                //http://forums.adobe.com/message/5393217#5393217
                                
                                //DESCRIPTION:SELECT THE WHOLE TEXT RANGE that contains all the paragraphs you want to renumber in reverse
                                
                                /**
                                * @@@BUILDINFO@@@ ReverseNumberingOfNumberedParagraphs_TEXTRANGE_SELECTION.jsx !Version! Tue Jun 11 2013 10:15:35 GMT+0200
                                */
                                
                                
                                app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
                                
                                if(app.selection.length !== 1 || !app.selection[0].hasOwnProperty("baselineShift")){
                                    alert("Select the WHOLE range of text you want to renumber in reverse. STOP.");
                                    exit(0);
                                    };
                                
                                app.doScript(_ReverseNumbering, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Reverse Numbering of Numbered Paragraphs");
                                
                                function _ReverseNumbering(){
                                
                                    var indexOfParagraphsAffected = new Array();
                                    var selectedParagraphs = app.selection[0].paragraphs;
                                    var counter = 0;
                                
                                    for(var n=0;n<selectedParagraphs.length;n++){
                                        
                                        //Are there any paragraphs that use list type NUMBERED_LIST ??
                                        //(Is blind to applied paragraph styles):
                                        if(selectedParagraphs[n].bulletsAndNumberingListType == ListType.NUMBERED_LIST){
                                            indexOfParagraphsAffected[counter]=n;
                                            ++counter;
                                            };
                                        
                                        };
                                
                                    for(var n=0;n<indexOfParagraphsAffected.length;n++){
                                        //Apply the current value of variable counter to Number Start:
                                        selectedParagraphs[indexOfParagraphsAffected[n]].properties = ({numberingContinue:false, numberingStartAt:counter});
                                        --counter;
                                        };
                                    
                                    alert(indexOfParagraphsAffected.length +"\t"+"paragraphs renumbered.");
                                
                                };
                                

                                 

                                You can undo the renumbering in one go.
                                The script checks, if you have selected some text.

                                 

                                Uwe

                                • 13. Re: How do I number paragraphs in reverse order high to low?
                                  ProtonAus Level 1

                                  Dear Uwe,

                                   

                                  That is fantastic and works exactly as claimed.  Being able to undo in one hit is a great advantage too!  Thank you so much!

                                   

                                  A small side-effect - sub paragraphs (a, b, c etc.) are also renumbered in a rather strange fashion (in this case a-f renumbered to bo-bj) with the 6 numbers then skipped in the main numbering sequence - this is no doubt because the script is blind to styles but looks for numbering.

                                   

                                  Dare I ask - any suggestions?

                                   

                                  Thanks again.

                                   

                                  ProtonAus

                                  • 14. Re: How do I number paragraphs in reverse order high to low?
                                    Laubender Adobe Community Professional & MVP

                                    @ProtonAus – I have to see into that…

                                     

                                    Ok. Yeah. The script is checking for lists of type NUMBERED_LIST. And that includes all kind of formats like "1,2,3", "01,02,03" and also "A,B,C" or "a,b,c".

                                     

                                    So we have to restrict its scope to the number format "1,2,3" (if you are using exactly this).


                                    Best would be, if you can provide a test case to download from a web service like Dropbox in IDML format.

                                     

                                    But until then just see line 36 of the script and change that:

                                     

                                    if(selectedParagraphs[n].bulletsAndNumberingListType == ListType.NUMBERED_LIST){
                                    

                                     

                                    for that:

                                     

                                    if(selectedParagraphs[n].bulletsAndNumberingListType == ListType.NUMBERED_LIST && selectedParagraphs[n].numberingFormat === "1, 2, 3, 4..."){
                                    

                                     

                                     

                                    Uwe

                                    • 15. Re: How do I number paragraphs in reverse order high to low?
                                      ProtonAus Level 1

                                      Uwe, that is brilliant!  Works perfectly.

                                       

                                      Thank you so much.

                                       

                                      This is probably a dumb question, but where do you find the list of attributes such as:

                                       

                                      selectedParagraphs[n].numberingFormat

                                       

                                      I can sort of see how to do this stuff, but am stumped by the approriate terms to use.

                                       

                                      Regards,

                                       

                                      ProtonAus.

                                      • 16. Re: How do I number paragraphs in reverse order high to low?
                                        Laubender Adobe Community Professional & MVP

                                        @ProtonAus – for once you can use the OMV (Object Model Viewer) in the ESTK (ExtendScript Toolkit) that is installed with every version of InDesign, but it's slow and daunting looking at possible properties and available methods.

                                         

                                        Sometimes your query will be answered with "Too much results to display" (or something along this). Adobe should change that!

                                         

                                        On the other hand we have a *fantastic(!)* reference of the DOM (Document Object Model) documented in search friendly file formats thanks to Jongware:

                                         

                                        http://www.jongware.com/idjshelp.html

                                         

                                        Adobe should have a built in feature in the ESTK that can read out that information directly to CHM files… But I fear, the ESTK is treated like the unwanted child of the family…

                                         

                                        This feature would especially valuable for scripters who installed (partly) scriptable plugins like the ADPS or 3rd party ones that allow some scripting.

                                         

                                        Uwe

                                        • 17. Re: How do I number paragraphs in reverse order high to low?
                                          ProtonAus Level 1

                                          Thanks Uwe (and Jongware of course) - that is fantastic and just what's needed.

                                           

                                          I should be able to tackle these things myself in future.

                                           

                                          Doesn't Adobe want us to use this facility?

                                           

                                          Thanks again for your great help - much appreciated!

                                           

                                          Regards,

                                           

                                          ProtonAus.