6 Replies Latest reply on Feb 22, 2012 3:52 PM by Peter Kahrel

    [CS5 JS] excluding Notes from find/change

    richardh6 Level 1

      Hello,

       

      Does anybody know a way to exclude all the text inside a Note from a find/change operation, either text or grep?

       

      I went through and systematically set all the findChangeGrepOptions that had the word 'include' in them to false:

       

      includeLockedStoriesForFind: false

      includeLockedLayersForFind: false

      includeHiddenLayers: false

      includeMasterPages: false

      includeFootnotes: false

       

      just to check, but nothing worked. myText.changeGrep() still changed the text inside the Notes.

       

      Of course, it would be fairly easy to write a wrapper function

       

      var myChangeGrep = function( textObject, checkNotes ) {
         checkNotes = checkNotes || false;
         results = [];
      
        // Go through and run changeGrep on all the 
        // parts of the textObject that are not contained inside Notes, 
        // (or just run it on the entire textObject if checkNotes is true),
        // and push the results to the results array as we go along.
      
        return results;
      };
      

       

      but this has the drawback that it returns an array and not an InDesign collection, like the regular changeGrep does. Also, as easy as this may be, it would be easier if there was a preference somewhere to take care of this.

       

      Any idea?

       

      Thanks!

        • 1. Re: [CS5 JS] excluding Notes from find/change
          Peter Kahrel Adobe Community Professional & MVP

          There is no preference for that: the scope of Find/Replace can be set only with the five preferences you already tried. (Similarly, you can't include/exclude tables.) findGrep() and changeGrep() return an array, by the way, not a collection.

          • 2. Re: [CS5 JS] excluding Notes from find/change
            richardh6 Level 1

            Thanks, Peter.

             

            That's good to hear about the return value of findGrep and changeGrep. I just assumed they were collections.

             

            I will write that wrapper function and post it up on this thread.

            • 3. Re: [CS5 JS] excluding Notes from find/change
              mcolmenero

              hi,

              how do I take in grep $0 or $1 or $2 in script?

              I´m looking in grep (\d?\d?\d?)(.?)(\d?\d?\d?)(,?)(\d?\d?) and I want to change ". " to "," and "," to" ." in numbers.

               

              I put "$1"+","+"$3+"."+$5

               

              I have in document these numbers:

              I have                I want

              1000                   1,000.00

              1.000,08             1,000.78

              100,78                   100.78

              9                                9.00

              9,78                           9.78

               

              Thanks for your help

               

               

              The script is:

              var myDoc = app.activeDocument;

               

              alert("begin");

              var numberfind= "(\d?\d?\d)(.?)(\d?\d?\d?)(,\d\d)";

              var numberchange ="$1"+","+"$3"+"."+"$5"; // I think here i have the problem

               

              for(var i =0; numberfind.length > i; i++)

                  {

                      var numWords = theGrepChanger(myDoc,numberfind[i],numberchange[i]) ;  

                  }

               

              alert("end");

               

               

              function theGrepChanger(docRef,grepFindIt,grepChangeIt)

                  {

                      app.findGrepPreferences = NothingEnum.NOTHING;

                      app.changeGrepPreferences = NothingEnum.NOTHING;

                      app.findGrepPreferences.findWhat = grepFindIt;

                      app.changeGrepPreferences.changeTo = grepChangeIt;

                      var arrGrepFindIt = myDoc.changeGrep();

                      return arrGrepFindIt;

               

                  }

              • 4. Re: [CS5 JS] excluding Notes from find/change
                Peter Kahrel Adobe Community Professional & MVP

                Please don't start a new topic in an existing thread. Anyway, you'd better use two separate GREPs for what you want: one to swap periods and commas, another one to add decimals to whole numbers. To swap periods and commas, look here: http://tinyurl.com/6m8squ4. To find numbers that don't contain periods of commas, you can use this grep: \b(?<![.,])\d+(?![,.])\b and use $0.00 or $0,00 as the replacement string.

                 

                Peter

                • 5. Re: [CS5 JS] excluding Notes from find/change
                  mcolmenero Level 1

                  hi Peter,

                  Thanks,

                  But i want to know how to tell grep structure in script $0, $1...

                  app.findGrepPreferences.findWhat ="(\\d?\\d?\\d)(.)(\\d\\d\\d)(,?)(\\d?\\d?)";

                          app.findGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item(myParagraphStyleName);

                          foundItems = app.activeDocument.findGrep();

                          alert ("foundItems "+foundItems.length);

                          for (var i=foundItems.length-1; i >=0; i--)

                          {

                              var result = foundItems[i].contents; // which is what I started with above

                              alert("Contenido "+result);

                              alert("$0 "+'$0');// like this, tell me $0 $0...How I tell $0 of grep

                              alert("$1 "+'$1');

                              alert("$2 "+'$2');

                              alert("$3 "+'$3');

                              alert("$4 "+'$4');

                              alert("$5 "+'$5');

                              result = result.replace (".", "");

                              result = result.replace (",", ".");

                              var result2=(parseFloat(result)*myPercentage);

                              result2 = String(result2);

                              foundItems[i].contents = result2;

                          }

                  Thansk for your help

                  • 6. Re: [CS5 JS] excluding Notes from find/change
                    Peter Kahrel Adobe Community Professional & MVP

                    Saying just "i want to know how to tell grep structure in script $0, $1...", then inserting a whole script, isn't particularly helpful.

                    But I think I know what you mean. You can't use JavaScript to display InDesign's $0, $1, etc. (not so easily anyway). To see what $0, $1, etc. are bound to, don't use your script, but do as follows. Create a new document, add a text frame and enter your sample list in the text frame:

                     

                    1000

                    1.000,08

                    100,78

                    9

                    9,78

                     

                    Then enter your grep expression in the Find What field, then enter just $0 in the Change To field, and press Change all. See what happens. (You could *** underline or a colour to make it better visible.). Undo, then add $1 into the Change To field, and look again what happens. Do the same for $2 etc. This way you can work out what each $n represents.

                     

                    Peter

                     

                     

                    Peter