3 Replies Latest reply on Jun 29, 2015 9:09 AM by Vamitul

    How to detect the actual level and index number of a numbered list item?

    dkancsar

      Hi All,

       

      I want to detect the actual level and index number of a numbered list item, E.g. if "4.4.1 mycontent" (where the numbered list id is "4.4.1" and the contents is only "mycontent") then I want to detect at least "3" as the level and "1" as the actual index number of the list. Do you know if there is any property of an IDS Object (E.g. ParagraphStyleRange, CharacterStyleRange...) what describes them somehow? Any help is appreciated!

       

      Thx,

      D

        • 1. Re: How to detect the actual level and index number of a numbered list item?
          Vamitul Level 4

          Paragraph.numberingLevel and Paragraph.numberingResultNumber should get you there.
          (InDesign ExtendScript API (10.0))

          1 person found this helpful
          • 2. Re: How to detect the actual level and index number of a numbered list item?
            dkancsar Level 1

            Hi Vamitul,

             

            Thanks for the reply. It helped me partially, but I have stucked in searching for the actual text of a listed item and in the similarities to sorted list. Could you give me directions, please. I want to detect "all" properties e.g. bold,italic,underlined,subscript,superscript,list level & index, the color and of couse the cotent of the text form char to char in a textframe. When I iterate throught the paragraphs of the textframe and the ranges of the paragraphs I can not receive all these properties of each chracter correctly. The paragraph.contents are correct but they do not declare the font styles e.g bold,italic of the char... On the other hand the range defines these properties, but there the content is the mixed somehow. Here I could not detect a fix "rule" yet. Sometimes the first range contents the whole text, sometimes the last one repeats the first range... And the sorted list has no numberingLevel value at all :-(

             

            Thanks for helping!

            D

             

            Here is an example textframe content:

             

            Bold

            italic

            underlined

            subscript

            superscript

            • Sorted List a
            • Sorted List b
            • Sorted List c
            1. Numbered List 1
            2. Numbered List 2
            3. Numbered List 3

            Colored

             

            Here is a short part of my javascript:

             

            ...

            var richtext = {

            getTextFrameContents:function(textFrame) {

                 var contents = '';

                 for(var p=0; p<textFrame.paragraphs.count(); p++) {

                        var par = textFrame.paragraphs[p];

                       

                        if( par.bulletsAndNumberingListType == ListType.BULLET_LIST

                                || par.bulletsAndNumberingListType == ListType.NUMBERED_LIST ) {

                            contents = contents + par.contents;

                            log.debug(" - " + (p+1) + ". par.contents ("+ par.contents.length + " #" + par.numberingLevel + "/" + par.numberingResultNumber + "): " + par.contents);

                            for(var t=0; t<par.textStyleRanges.count(); t++) {

                                var range = par.textStyleRanges[t];

                                log.debug("       range ("+range.contents.length+"): " + range.contents);

                            }

                        }

                        else {

                            for(var t=0; t<par.textStyleRanges.count(); t++) {

                                var range = par.textStyleRanges[t];

                                var rangeContent = '';

                                for(r=0; r<range.contents.length; r++) {

                                    var code = range.contents.charCodeAt(r);

                                    rangeContent = rangeContent + range.contents[r];

                                }

                                contents = contents + rangeContent;

                                log.debug(" - " + (p+1) + ". range.contents ("+rangeContent.length + "): " + rangeContent);

                            }

                        }

                    }

                    log.debug("tf (" + textFrame.contents.length + "): " + textFrame.contents);

                    log.debug("contents (" + contents.length + "): " + contents);

                    return contents;

                }

            };

             

            And the console:

             

            - 1. range.contents (5): Bold

            - 2. range.contents (7): Italic

            - 3. range.contents (11): Underlined

            - 4. range.contents (3): Sub

            - 4. range.contents (7): script

            - 5. range.contents (5): Super

            - 5. range.contents (7): script

            - 6. par.contents (14 #1/-1): Sorted List a

                  range (6): Sorted

                  range (8):  List a

            - 7. par.contents (14 #1/-1): Sorted List b

                  range (6): Sorted

                  range (8):  List b

            - 8. par.contents (14 #1/-1): Sorted List c

                  range (6): Sorted

                  range (8):  List c

            - 9. par.contents (16 #1/1): Numbered List 1

                  range (9): Numbered

                  range (4): List

                  range (12):  1

            - 10. par.contents (16 #1/2): Numbered List 2

                  range (9): Numbered

                  range (4): List

                  range (12):  2

            - 11. par.contents (16 #1/3): Numbered List 3

                  range (9): Numbered

                  range (4): List

                  range (3):  3

            - 12. range.contents (10): Text color

            tf (145): Bold

            contents (145): Bold

            • 3. Re: How to detect the actual level and index number of a numbered list item?
              Vamitul Level 4

              ok. I see what you are trying to do, and it won't really work like that. The best way would be something like (assuming a text selection):

              var paras=app.activeDocument.selection[0].paragraphs.everyItem().getElements(); //get an array of the paragraphs
              for (var i=0;i<paras.length; i++){
                paras[i].convertBulletsAndNumberingToText(); //flatten the lists to get everything
                var ranges=paras[i].textStyleRanges.everyItem().getElements();
                for (var j=0;j<ranges.length;j++){
                $.writeln(ranges[j].texts[0].contents);//using the ".texts[0]" trick to get over Special Characters Enumerators
                $.writeln(ranges[j].fontStyle); //bold, italic, whatever
                $.writeln(ranges[j].underline); //true or false
                //add whatever properties you need here.
                }
              }
              
              

               

              This should work.. if not, you might need to go through your document character by character and that is painfully slow.