12 Replies Latest reply on Oct 21, 2014 4:55 PM by creativejoan0425

    GREP Problems

    creativejoan0425 Level 1

      Hi experts,

       

      I want to check the bracket with specific font and alert which page, but when I run the script, it cause indesign crash, it is something wrong with my script, please help me to fix it

       

      below is my script:

       

       

      checkBracket();

      function checkBracket(){

       

          app.findGrepPreferences = NothingEnum.nothing;

          app.changeGrepPreferences = NothingEnum.nothing;

         

          app.findChangeGrepOptions.includeFootnotes = true;

          app.findChangeGrepOptions.includeHiddenLayers = true;

          app.findChangeGrepOptions.includeLockedLayersForFind = true;

          app.findChangeGrepOptions.includeLockedStoriesForFind = true;

          app.findChangeGrepOptions.includeMasterPages = true;

          app.findChangeGrepOptions.widthSensitive = true;

          app.findGrepPreferences.findWhat="\(|\)";

          app.findGrepPreferences.appliedFont = app.fonts.item("DIN Light");

          app.findGrepPreferences.fontStyle = "Regular";

         var myList = "";

       

       

         var myfindGrep=app.findGrep();

          for(i=0; i<myfindGrep.length; i++)

          {

              var item = myfindGrep[i];

              var page = item.parentTextFrames[0].parentPage;

              myList += page.parent.parent.name + " (Page: "+page.name +")\n";

          }//end of loop

        if (item.length>0) {

        alert("Below document(s) have wrong rounded bracket () :\n\n"+ myList +"\nPlease Global");

        }//end of if

      else {alert("no");}

          app.findGrepPreferences = NothingEnum.nothing;

          app.changeGrepPreferences = NothingEnum.nothing;

       

       

      }//end of function

        • 1. Re: GREP Problems
          Peter Kahrel Adobe Community Professional & MVP

          1. If what you find is in overset text, it doesn't have any parentTextFrames, so you should guard against that:

           

          if (item.parentTextFrames[0] != undefined) {

             var page = item.parentTextFrames[0].parentPage;

             myList += page.parent.parent.name + " (Page: "+page.name +")\n";

          }

           

          2. Use app.documents[0].findGrep() instead of app.findGrep().

           

          But anyway, InDesign shouldn't crash. If you can repeat the crash, file a bug report.

           

          Peter

          • 2. Re: GREP Problems
            creativejoan0425 Level 1

            Hi Peter,

             

            I download the pdf "Beginning ScriptUI" from you

             

            On page 63

            I want to alert all col2.text even col2 text has been changed (for example, I change Alpha to 1, and Bravo to 2),  but without onChanging the sbar, but I can only alert

            "1", "2", "Charlie", Delta", "Echo", "Foxtrot", Golf", "Hotel", India", "Juliet"

            How can alert all?

             

             

             

            var call_codes = {"A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India",

            "J": "Juliet", "K": "Kilo", "L": "Lima", "M": "Mike", "N": "November", "O": "Oscar", "P": "Papa", "Q": "Quebec", "R": "Romeo", "S": "Sierra", "T":

            "Tango", "U": "Uniform", "V": "Victor", "W": "Whiskey", "X": "X-ray", "Y": "Yankee", "Z": "Zulu"};

            var rows = 10, number_of_codes = 0;

            for (var i in call_codes) number_of_codes++; // We need to know how many elements the object contains

            var w = new Window ("dialog");

            var group = w.add ("group {alignChildren: 'fill'}");

            var panel = group.add ("panel {orientation: 'row', alignChildren: 'top'}");

            var sbar = group.add ("scrollbar {preferredSize: [20, undefined], maxvalue: " + String (number_of_codes-rows) + "}");

            var col1 = panel.add ("group {orientation: 'column', margins: 3}");

            var col2 = panel.add ("group {orientation: 'column', alignChildren: 'fill', preferredSize: [150, undefined]}");

            myText1Array =[];

            var fields = {}, start = 0, stop = rows, n = -1, myCheck = {};

            for (var i in call_codes){

            ++n;

            if (n >= start && n < stop){

            myCheck[n]  =col1.add ("statictext", [0, 0, 20, 22], i);

            fields[n] = col2.add ("edittext", undefined, call_codes[i]);

            fields[n].label = i; // Add a label property that contains the letter

            fields[n].onChange = function () {call_codes[this.label] = this.text}

            } // When the edittext is changed, update the call_codes object

            }

            sbar.onChanging = function()

            {

            myTextArray = [];

            var start = Math.round (this.value); // Round the sbar's value

            var stop = start+rows, n = 0, r = -1;

            for (var i in call_codes)

            {

            n++;

             

             

            if (n > start && n <= stop)

            {

            ++r;

            col1.children[r].text = i; // Replace the contents of the statictext

            fields[r].text = call_codes[i]; // and the edittext controls

            fields[r].label = i; // and update each edittext's label

            }

            }

            }

            w.show();

            for (var i=0; i<26; i++){

            alert(col2.children[i].text);

            }

            • 3. Re: GREP Problems
              Peter Kahrel Adobe Community Professional & MVP

              Hello Joan,

               

              At the end of the script, remove these lines:

               

              for (var i=0; i<26; i++){

                  alert(col2.children[i].text);

              }

               

              and add these:

               

              for (var i in call_codes) {

                  alert (call_codes[i]);

              }

               

               

              Peter

               

               

              On Wed, 08 Oct 2014 01:02:46 +0100, creativejoan0425

              • 4. Re: GREP Problems
                creativejoan0425 Level 1

                Hi Peter,

                 

                How about these one, I open 10 documents, and each files have different total pages, at the end I want to alert all Checkbox value but I juz can alert 5 times, for the edit content I want to alert all, it can alert all but when I change the contents, the result did change

                 

                var DocArray = app.documents.everyItem().name;

                var myPrintFiles =[];

                var myPagesLength =[];

                 

                 

                for (i = 0; i < DocArray.length; i++){

                                                myPrintFiles.push(app.documents.itemByName(DocArray[i]).name);

                                                myPagesLength.push(app.documents.itemByName(DocArray[i]).pages.length);

                                        }

                var call_codes = {myPrintFiles: myPagesLength};

                var rows = 5, number_of_codes = DocArray.length;

                var w = new Window ("dialog");

                var group = w.add ("group {alignChildren: 'fill'}");

                var panel = group.add ("panel {orientation: 'row', alignChildren: 'top'}");

                var sbar = group.add ("scrollbar {preferredSize: [20, undefined], maxvalue: " + String (number_of_codes-rows) + "}");

                var col1 = panel.add ("group {orientation: 'column', margins: 3}");

                var col2 = panel.add ("group {orientation: 'column', alignChildren: 'fill', preferredSize: [150, undefined]}");

                var fields = {}, start = 0, stop = rows, n = -1, myCheck = {};

                 

                 

                         var myPrintFilesJoin =  myPrintFiles.join("\\r");

                                    var myPrintFilesSplit =  myPrintFilesJoin.split("\\r");

                                          for (j = 0; j < myPrintFilesSplit.length; j++) {

                                                   myEachEditContent = myPrintFilesSplit[j];

                 

                 

                for (var i in call_codes){

                ++n;

                if (n >= start && n < stop){

                myCheck[n]  =col1.add ("checkbox", [0, 0, 300, 22], myPrintFilesSplit[j]);

                fields[n] = col2.add ("edittext", undefined, myPagesLength[j].toString().split(","));

                fields[n].label = i; // Add a label property that contains the letter

                fields[n].onChange = function () {call_codes[this.label] = this.text}

                } // When the edittext is changed, update the call_codes object

                }

                }

                sbar.onChanging = function()

                {

                var start = Math.round (this.value); // Round the sbar's value

                var stop = start+rows, n = 0, r = -1;

                var myPrintFilesSplit =  myPrintFilesJoin.split("\\r");

                for (j = 0; j < myPrintFilesSplit.length; j++) {

                 

                 

                //~ for (var i in call_codes)

                //~ {

                n++;

                 

                 

                if (n > start && n <= stop)

                {

                ++r;

                col1.children[r].text = myPrintFilesSplit[j]; // Replace the contents of the statictext

                fields[r].text = myPagesLength[j].toString().split(","); // and the edittext controls

                fields[r].label = i; // and update each edittext's label

                 

                 

                }

                }

                }

                 

                 

                w.show();

                for (j = 0; j < 10; j++) {

                alert(myPagesLength[j].toString().split(","));

                }

                for (j = 0; j < 10; j++) {

                alert(col1.children[j].value);

                }

                 

                Thanks and Best Regards

                Joan

                • 5. Re: GREP Problems
                  Peter Kahrel Adobe Community Professional & MVP

                  Sorry Joan, I don't see how your latest query relates to the earlier one. 

                  And I really haven't a clue what you mean with "How about . . . did 

                  change".

                   

                  Peter

                  • 6. Re: GREP Problems
                    creativejoan0425 Level 1

                    For example I open 10 indd file called 1.indd, 2.indd, 3.indd, 4.indd, 5.indd, 6.idd, 7.indd, 8.indd, 9.indd, 10.indd

                    and each file have different pages 1.indd (1 page), 2.indd (2 pages), 3.indd (3 pages), 4.indd (4 pages), 5.indd (5 pages), 6.idd (6 pages), 7.indd (7 pages), 8.indd (8 pages), 9.indd (9 pages), 10.indd (10 pages)

                     

                    For Row1 editcontent, I change 9 to 20 and Row 2 change from 8 to 21

                    Only Row 1, 3, 5 Checkbox value is true

                     

                    so If I alert all editcontent it should be 20, 21, 7, 6, 5, 4, 3, 2, 10, 1

                    but the result is 9, 8, 7, 6, 5, 4, 3, 2, 10,1

                     

                    and for the Checkbox value, the result should be true, false, false, true, true, false, false, false, false, false

                    but now the result true, false, false, true, true

                    qqq.jpg

                    • 7. Re: GREP Problems
                      creativejoan0425 Level 1

                      Hi Peter,

                       

                      And I found that when I change the row 1 9 to 20 and then I use the scrollbar to scroll down and then scroll up , 20 will change back to 9, can make it when I scroll back the result is 20?

                      • 8. Re: GREP Problems
                        Peter Kahrel Adobe Community Professional & MVP

                        I'm not sure how checkboxes behave in that scrollbar method, and I can't investigate it now. If I were you I would use a simple non-scrolling list.

                        • 9. Re: GREP Problems
                          creativejoan0425 Level 1

                          I try to use the non-scrolling list, but sometimes I need open about 40 indd files at once. so the list is too long and can't see , can the script ui dialog auto flow in other column in these case?

                          • 10. Re: GREP Problems
                            Peter Kahrel Adobe Community Professional & MVP

                            Well, you can place the list in two or three columns. No need for autoflow.

                            • 11. Re: GREP Problems
                              creativejoan0425 Level 1

                              Thx a lots, I try 

                              從三星手機發送

                              • 12. Re: GREP Problems
                                creativejoan0425 Level 1

                                Hi Peter,

                                 

                                I cant alert all checkbox value, and editcontent even when change the text but I have a little problem, If for example checkbox 1 value is true, checkbox 2 value is false, I click the checkbox 2 , and the value become true, then I use the scrollbar , scroll down and scroll up, the result still is the first what I see, can u help me to fix it?

                                 

                                var DocArray = app.documents.everyItem().name;

                                var myPrintFiles =[];

                                var myPagesLength =[];

                                                    DocArray.sort();

                                var myCol1ValueArray = [];

                                var myCol1ValueArray1 = [];

                                for (i = 0; i < DocArray.length; i++){

                                                myPrintFiles.push(app.documents.itemByName(DocArray[i]).name);

                                                myPagesLength.push(app.documents.itemByName(DocArray[i]).pages.length);

                                                myCol1ValueArray.push("false");

                                                }

                                var call_codes1 = myPrintFiles;

                                var call_codes2 = myPagesLength;

                                var rows =5, number_of_codes = 0;

                                for (var i in call_codes1) number_of_codes++; // We need to know how many elements the object contains

                                var w = new Window ("dialog");

                                var group = w.add ("group {alignChildren: 'fill'}");

                                var panel = group.add ("panel {orientation: 'row', alignChildren: 'top'}");

                                var sbar = group.add ("scrollbar {preferredSize: [20, undefined], maxvalue: " + String (number_of_codes-rows) + "}");

                                var col1 = panel.add ("group {orientation: 'column', margins: 3}");

                                var col2 = panel.add ("group {orientation: 'column', alignChildren: 'fill', preferredSize: [150, undefined]}");

                                var fields = {}, start = 0, stop = rows, n = -1, myCheck = {}, m=-1;

                                 

                                 

                                 

                                 

                                for (var i in call_codes2){

                                ++n;

                                if (n >= start && n < stop){

                                myCheck[n]  =col1.add ("checkbox", [0, 0, 300, 22], call_codes1[i]);

                                fields[n] = col2.add ("edittext", undefined, call_codes2[i]);

                                fields[n].label = i; // Add a label property that contains the letter

                                var myCol_1 = myCheck[n];

                                fields[n].onChange = function () {

                                call_codes2[this.label] = this.text;

                                }

                                myCheckBoxText = call_codes2[i];

                                if(myCheckBoxText.toString().match(/9/)){

                                col1.children[i].value = false;

                                }

                                else{

                                col1.children[i].value = true;

                                }

                                 

                                 

                                }

                                }

                                for (var i in call_codes2){

                                myCheckBoxText = call_codes2[i];

                                if(myCheckBoxText.toString().match(/9/)){

                                myCol_1.value = false;

                                }

                                else{

                                myCol_1.value = true;

                                }

                                myCol1ValueArray1.push(myCol_1.value);

                                }

                                for (var i in myCol1ValueArray){

                                ++m;

                                if (m >= start && m < stop){

                                myCheck[m].label = i;

                                myCheck[m].onClick = function () {

                                    myCol1ValueArray1[this.label] = this.value;

                                }

                                 

                                 

                                } // When the edittext is changed, update the call_codes object

                                }

                                 

                                 

                                sbar.onChanging = function(){

                                var start = Math.round (this.value); // Round the sbar's value

                                var stop = start+rows, n = 0, r = -1, m=0, s=-1;

                                for (var i in call_codes2){

                                n++;

                                if (n > start && n <= stop){

                                ++r;

                                col1.children[r].text = call_codes1[i]; // Replace the contents of the statictext

                                fields[r].text = call_codes2[i];// and the edittext controls

                                 

                                 

                                fields[r].label = i; // and update each edittext's label

                                //~ alert(call_codes2[i]);

                                myCheckBoxText = call_codes2[i];

                                if(myCheckBoxText.toString().match(/9/)){

                                col1.children[r].value = false;

                                }

                                else{

                                col1.children[r].value = true;

                                }

                                 

                                 

                                myCol1ValueArray1.push(myCheck[r].value);}

                                 

                                 

                                 

                                 

                                }

                                 

                                 

                                 

                                 

                                for (var i in myCol1ValueArray){

                                m++;

                                if (m > start && m <= stop){

                                ++s;

                                myCheck[s].label =i;

                                myCheck[s].onClick = function () {

                                    myCol1ValueArray1[this.label] = this.value;

                                }

                                 

                                 

                                }

                                }

                                }

                                w.show();

                                 

                                 

                                for (var i in call_codes2){

                                alert(call_codes2[i]);

                                }

                                 

                                 

                                for (var i in myCol1ValueArray){

                                alert(DocArray[i]+", "+myCol1ValueArray1[i]);

                                 

                                }

                                 

                                Many Thanks

                                Joan