10 Replies Latest reply on Oct 2, 2018 1:20 AM by [Jongware]

    Find string of paragraph numbering

    carlp33822801 Level 1

      So I've made a script to change data in multiple tables. I want to target each table by looking for an index-number. This index-number is generated with a Paragraph Style Bullets & numberings (then using just a space to print that) inside a table cell. I wonder, is there anyway to actually target that value?

       

      Here's a rough example:

       

      Table oneindex_0
      Value 1value 2
      Value 3Value 4

       

      Table Twoindex_1
      Value 1value 2
      Value 3Value 4

       

       

      Here's my code that works with normal text in a cell:

       

      app.findGrepPreferences.findWhat = "index_0"; // Find table with index  
      
        • 1. Re: Find string of paragraph numbering
          Level 4

          Hi,

           

          … For doing what after? …

           

          Best,

          Michel, for FRIdNGE

          • 2. Re: Find string of paragraph numbering
            Peter Kahrel Adobe Community Professional & MVP

            Use the paragraph's bulletsAndNumberingResultText property.

            1 person found this helpful
            • 3. Re: Find string of paragraph numbering
              carlp33822801 Level 1

              Well, it doesn't really matter for the question in hand, but to match tables with an array of variables and then inserting them as data in the tables.

              • 4. Re: Find string of paragraph numbering
                carlp33822801 Level 1

                Sorry, pretty new to inDesign-scripting could you give a code example please?

                • 5. Re: Find string of paragraph numbering
                  Level 4

                  Carl,

                   

                  Give a sample with screenshots!! Thanks! …

                   

                  Best,

                  Michel

                  • 6. Re: Find string of paragraph numbering
                    carlp33822801 Level 1

                    Here's a full example of my code (more items in wee though, just left two in there, will that help?

                    var week_2020_1 = {
                        index: "item_0",
                    week: "Vecka 1",
                        month: "December",
                        year: "2020",
                        monday: {
                            date: "31",
                            spec: "Nyårsafton",
                            name: "Sylvester",
                            holiday: true
                        },
                        tuesday: {
                            date: "01",
                            spec: "Nyårsdagen",
                            name: "",
                            holiday: true
                        },
                        wednesday: {
                            date: "02",
                            spec: "",
                            name: "Svea",
                            holiday: false
                        },
                        thursday: {
                            date: "03",
                            spec: "",
                            name: "Alfred, Alfrida",
                            holiday: false
                        },
                        friday: {
                            date: "04",
                            spec: "",
                            name: "Rut",
                            holiday: false
                        },
                        saturday: {
                            date: "05",
                            spec: "",
                            name: "Hanna, Hannele",
                            holiday: false
                        },
                        sunday: {
                            date: "06",
                            spec: "",
                            name: "Kasper, Melker, Baltsar",
                            holiday: true
                        }
                    }
                    var week_2020_2 = {
                        index: "item_1",
                    week: "Vecka 2",
                        month: "Januari",
                        year: "2020",
                        monday: {
                            date: "07",
                            spec: "",
                            name: "August, Augusta",
                            holiday: false
                        },
                        tuesday: {
                            date: "08",
                            spec: "",
                            name: "Erland",
                            holiday: false
                        },
                        wednesday: {
                            date: "09",
                            spec: "",
                            name: "Gunnar, Gunder",
                            holiday: false
                        },
                        thursday: {
                            date: "10",
                            spec: "",
                            name: "Sigurd, Sigbritt",
                            holiday: false
                        },
                        friday: {
                            date: "11",
                            spec: "",
                            name: "Jan, Jannike",
                            holiday: false
                        },
                        saturday: {
                            date: "12",
                            spec: "",
                            name: "Frideborg, Fridolf",
                            holiday: false
                        },
                        sunday: {
                            date: "13",
                            spec: "",
                            name: "Knut",
                            holiday: true
                        }
                    }
                    
                    
                    
                    
                    var weeks = {
                        item_0: week_2020_1,
                        item_1: week_2020_2,
                    }
                    
                    
                    
                    
                    for (var item in weeks) {
                    //alert(weeks[item]['week']);
                    //updateWeekTablesData(weeks[item]);
                    insertWeekTablesData(weeks[item]);
                    }
                    
                    
                    
                    
                    /* UPDATE WEEK TABLES */
                    function updateWeekTablesData(itemData) {
                    
                    app.findGrepPreferences = app.changeGrepPreferences =null; 
                    app.findGrepPreferences.findWhat = itemData["index"]; // Find table with index     
                    
                    var found = app.documents[0].findGrep(); 
                    
                    
                    for(i=0; i<found.length; i++) 
                    { 
                        if(found[i].contents) 
                        { 
                       
                        found[i].select(); 
                        alert(found[i].contents);
                        replaceData();
                        }   
                    } 
                    
                    
                    app.findGrepPreferences = app.changeGrepPreferences =null; 
                       
                       
                    function replaceData() {
                    
                        var source = app.selection[0].parent.parentColumn;
                        var table = source.parent; //Target table of selection
                    
                    function newMonthData(newMonth, newYear) {
                    //ri = row index
                    //ci = column index
                    
                    var tableCell = {
                        month : table.rows[1].cells[10],
                        year : table.rows[1].cells[11],
                        }
                    
                        tableCell["month"].texts[0].contents = newMonth;
                    tableCell["year"].texts[0].contents = newYear;
                    
                    
                        return newMonthData;
                    }
                    
                    var monthyear = newMonthData(itemData["month"], itemData["year"]);
                    
                    
                    function newDayData(ri, ci, newDate, newSpec, newName, holiday) {
                    //ri = row index
                    //ci = column index
                    
                    var tableCell = {
                        date : table.rows[0 + ri].cells[0 + ci],
                        day : table.rows[1 + ri].cells[0 + ci],
                    spec : table.rows[0 + ri].cells[1 + ci],
                    name : table.rows[1 + ri].cells[1 + ci]
                        }
                    
                        tableCell["date"].texts[0].contents = newDate;
                    tableCell["spec"].texts[0].contents = newSpec;
                    tableCell["name"].texts[0].contents = newName;
                    
                    
                    if (holiday == true) {
                    tableCell["date"].appliedCellStyle = "date-holiday";
                    tableCell["day"].appliedCellStyle = "day-holiday";
                    } else {
                    tableCell["date"].appliedCellStyle = "date";
                    tableCell["day"].appliedCellStyle = "day";
                    }
                    
                    
                    if (newDate == itemData["sunday"]["date"] || newDate == itemData["saturday"]["date"]) {
                    tableCell["spec"].texts[0].contents = newName;
                    tableCell["name"].texts[0].contents = newSpec;
                    }
                    
                        return newDayData;
                    
                    }
                    
                    var monday = newDayData(0, 0, itemData["monday"]["date"], itemData["monday"]["spec"], itemData["monday"]["name"], itemData["monday"]["holiday"]);
                    var tuesday = newDayData(0, 2, itemData["tuesday"]["date"], itemData["tuesday"]["spec"], itemData["tuesday"]["name"], itemData["tuesday"]["holiday"]);
                    var wednesday = newDayData(0, 4, itemData["wednesday"]["date"], itemData["wednesday"]["spec"], itemData["wednesday"]["name"], itemData["wednesday"]["holiday"]);
                    var thursday = newDayData(0, 6, itemData["thursday"]["date"], itemData["thursday"]["spec"], itemData["thursday"]["name"],itemData["thursday"]["holiday"]);
                    var friday = newDayData(0, 8, itemData["friday"]["date"], itemData["friday"]["spec"], itemData["friday"]["name"], itemData["friday"]["holiday"]);
                    var saturday = newDayData(2, 0, itemData["saturday"]["date"], itemData["saturday"]["spec"], itemData["saturday"]["name"], itemData["saturday"]["holiday"]);
                    var sunday = newDayData(4, 0, itemData["sunday"]["date"], itemData["sunday"]["spec"], itemData["sunday"]["name"], itemData["sunday"]["holiday"]);
                    }
                    }
                    
                    • 7. Re: Find string of paragraph numbering
                      Peter Kahrel Adobe Community Professional & MVP

                      The first step in your script would be to replace the automatic paragraph numbers with literal text. Something like this (Select the frame that contains the table):

                       

                      cells = app.selection[0].tables[0].cells.everyItem().getElements();
                      for (i = 0; i < cells.length; i++) {
                        if (cells[i].paragraphs[0].bulletsAndNumberingListType == ListType.NUMBERED_LIST) {
                          cells[i].paragraphs[0].contents = cells[i].paragraphs[0].bulletsAndNumberingResultText;
                        }
                      }
                      

                       

                      Then disable automatic paragraph numbering in the paragraph style. Maybe another approach is more efficient, depends on what your table looks like.

                       

                      P.

                      1 person found this helpful
                      • 8. Re: Find string of paragraph numbering
                        carlp33822801 Level 1

                        So, there's no way to actually search the output of a numbered list without converting it?
                        I'll try this and see if it works alright

                        • 9. Re: Find string of paragraph numbering
                          carlp33822801 Level 1

                          I used code above, but used a GREP-search instead:

                           

                          f

                          unction convertIndexToString () {
                          app.findGrepPreferences = app.changeGrepPreferences = null;
                          app.findGrepPreferences.findWhat = "\\b\\w+?\\b";
                          app.findGrepPreferences.appliedParagraphStyle = "vecka.index";
                          indexFound = app.activeDocument.findGrep();
                          
                          if (indexFound) {
                          for (f = 0; f < indexFound.length; f++ ) {
                                    thisItem = indexFound[f];
                                         if (thisItem.paragraphs[0].bulletsAndNumberingListType == ListType.NUMBERED_LIST) {
                                             thisItem.paragraphs[0].contents = thisItem.paragraphs[0].bulletsAndNumberingResultText; 
                                        }
                                     }
                               }
                          }
                          
                          
                          
                          
                          
                          • 10. Re: Find string of paragraph numbering
                            [Jongware] Most Valuable Participant

                            I don't understand how your marked self-answer answers the question. To check, I attempted to run your script but I don't see what it should be run on.

                             

                            What does "search the output of a numbered list without converting it" mean? If you have a numbered list "1, 2, 3" and you want to search for "2", yeah, that won't work. But you can iterate over the list and inspect their "bulletsAndNumberingResultText". Basically, what Peter said two weeks ago.