12 Replies Latest reply on Mar 2, 2009 5:40 AM by robin521

    it can not search the text with Grep, what's wronge with my code?

    robin521 Level 1
      Hi scripter,

      I got a Arabian files that include English and arabian fonts, but i need to find Arabian to change Fonts style. my grep may got some pro. please see the below:

      //Clear the find/change preferences.
      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences = NothingEnum.nothing;
      //Set the find options.
      app.findChangeGrepOptions.includeFootnotes = false;
      app.findChangeGrepOptions.includeHiddenLayers = false;
      app.findChangeGrepOptions.includeLockedLayersForFind = false;
      app.findChangeGrepOptions.includeLockedStoriesForFind = false;
      app.findChangeGrepOptions.includeMasterPages = false;
      //Regular expression for finding an email address.
      app.findGrepPreferences.findWhat = "[^A-Za-z0-9/.-]+";
      //Apply the change to 24-point text only.
      app.findGrepPreferences.pointSize = 24;
      app.changeGrepPreferences.underline = true;
      app.documents.item(0).changeGrep();
      //Clear the find/change preferences after the search.
      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences = NothingEnum.nothing;
        • 1. Re: it can not search the text with Grep, what's wronge with my code?
          Adobe-InDesign CS4 Level 1
          Dear robin521,

          I saw your code, and below I have to change the code

          Your code :
          //Regular expression for finding an email address.
          app.findGrepPreferences.findWhat = "[^A-Za-z0-9/.-]+";

          Change Code:
          //Regular expression for finding an email address.
          app.findGrepPreferences.findWhat = [A-Za-z0-9._%-]+@(?:[A-Za-z0-9-]+\.)+([A-Za-z]*)

          Please use the above code and get correct answers, Let me know if you have any queries.

          Thanks & Regards
          T.R.Harihara SudhaN
          • 2. Re: it can not search the text with Grep, what's wronge with my code?
            Peter Kahrel Adobe Community Professional & MVP
            Do you want to find Arabic or email addresses? Whichever, in your other topic on the same subject I replied that your GREP is faulty:
            >app.findGrepPreferences.findWhat = "[^A-Za-z0-9/.-]+";

            should be
            >app.findGrepPreferences.findWhat = "[^A-Za-z0-9\\.-]+";

            But this isn't going to find Arabic or email addresses: it finds everything that's not an unaccented Latin letter, a digit, dot, or hyphen.

            Peter
            • 3. Re: it can not search the text with Grep, what's wronge with my code?
              robin521 Level 1
              Hi Peter,

              yes, you are right! I need to find Arabic and i have been change my Grep, But there are still has no responses with my Indesign.



              if(app.documents.length ==0){
              alert("您没有打开任何文档!");
                  }

              //Clear the find/change preferences.
              app.findGrepPreferences = NothingEnum.nothing;
              app.changeGrepPreferences = NothingEnum.nothing;
              //Set the find options.
              app.findChangeGrepOptions.includeFootnotes = false;
              app.findChangeGrepOptions.includeHiddenLayers = false;
              app.findChangeGrepOptions.includeLockedLayersForFind = false;
              app.findChangeGrepOptions.includeLockedStoriesForFind = false;
              app.findChangeGrepOptions.includeMasterPages = false;
              //找到匹配的阿拉伯文文字进行修改.
              app.findGrepPreferences.findWhat = "[^A-Za-z0-9\\.-]+";
              app.changeGrepPreferences.underline = true;
              app.documents.item(0).changeGrep();
              //Clear the find/change preferences after the search.
              app.findGrepPreferences = NothingEnum.nothing;
              app.changeGrepPreferences = NothingEnum.nothing;

              • 4. Re: it can not search the text with Grep, what's wronge with my code?
                [Jongware] Most Valuable Participant
                The

                >findWhat

                specifies what is searched for. You'll have to change that.
                • 5. Re: it can not search the text with Grep, what's wronge with my code?
                  Peter Kahrel Adobe Community Professional & MVP
                  How is the Arabic coded? In your InDesign document, select a character which you expected to be found but isn't and press F8 to display the Info panel. Somewhere in the centre of the panel you see "Unicode: " followed by a unicode value. Tell us what you see there.

                  Peter
                  • 6. Re: it can not search the text with Grep, what's wronge with my code?
                    robin521 Level 1
                    Hi peter,

                    Sorry for late, i can not post my message.
                    I got it, Cause of low memory, I have already change it, but how can i change desiredWordSpacing=130 what i find? I need to change all character to desiredWordSpacing=130.


                    try{
                    if(app.documents.length ==0){
                    alert("您没有打开任何文档!");
                    }
                    }
                    catch(e){

                    }

                    //Clear the find/change preferences.
                    app.findGrepPreferences = NothingEnum.nothing;
                    app.changeGrepPreferences = NothingEnum.nothing;
                    //Set the find options.
                    app.findChangeGrepOptions.includeFootnotes = false;
                    app.findChangeGrepOptions.includeHiddenLayers = false;
                    app.findChangeGrepOptions.includeLockedLayersForFind = false;
                    app.findChangeGrepOptions.includeLockedStoriesForFind = false;
                    app.findChangeGrepOptions.includeMasterPages = false;
                    //找到匹配的阿拉伯文文字进行修改.
                    app.findGrepPreferences.findWhat = "[^A-Za-z0-9\\.-]+";
                    app.changeGrepPreferences.appliedFont="Arial"
                    app.documents.item(0).changeGrep();
                    //Clear the find/change preferences after the search.
                    app.findGrepPreferences = NothingEnum.nothing;
                    app.changeGrepPreferences = NothingEnum.nothing;

                    • 7. Re: it can not search the text with Grep, what's wronge with my code?
                      Peter Kahrel Adobe Community Professional & MVP
                      desiredWordSpace applies to paragraphs. What you're after is probably tracking.

                      Peter
                      • 8. Re: it can not search the text with Grep, what's wronge with my code?
                        robin521 Level 1
                        Hi Peter,

                        when i found the text base on GREP, Need to increase 30 percent PointSize and change font, Now, I found that needn't to change desiredWordSpacing, PointSize is ok.(pointSize*1.3)

                        I have two questions, how can i get the fontlist of current document and display on menu or dialogs, can i return a int in order to increase pointSize.

                        Thanks very much.
                        Regards,
                        Robin
                        • 9. Re: it can not search the text with Grep, what's wronge with my code?
                          Peter Kahrel Adobe Community Professional & MVP
                          >I have two questions, how can i get the fontlist of current document and display on menu or dialogs

                          Just get an array of font names, probably something like myDoc.fonts.everyItem().name and display it in a dropdown list in a dialog.

                          >can i return a int in order to increase pointSize.

                          Sure.

                          Peter
                          • 10. Re: it can not search the text with Grep, what's wronge with my code?
                            robin521 Level 1
                            Hi Peter,

                            how can i get current fonts style and pointsize when i search it by grep, i mean, i need to find the word by grep but when this fonts is different style i need to change it and different pointsize also.


                            main();
                            function main(){
                            if(app.documents.length != 0){
                              if(app.activeDocument.pageItems.length != 0){
                             
                              }
                              else{
                               alert("Document contains no page items.");
                              }
                            }
                            else{
                              alert("Please open a document and try again.");
                            }
                            }

                            var MyFontList=new Array;

                            MyFontList=app.fonts.everyItem().name;


                            var MyDialog=app.dialogs.add({name:"change your heart"});
                            with(MyDialog){

                            with(dialogColumns.add()){
                              with(borderPanels.add()){
                              staticTexts.add({staticLabel:"target:"});
                              }
                            with(dialogColumns.add()){
                              var myMenu=dropdowns.add();
                              myMenu.stringList=MyFontList;
                              myMenu.selectedIndex=0;

                              }
                            }
                            var myResult=MyDialog.show();
                            if(myResult== true )
                            {
                                var changeWord=myMenu.selectedIndex;
                              var changeTo=app.fonts[changeWord].name;
                            alert("you cange the font to"+changeTo)
                                FindGrep();

                            }

                            else{
                            alert ("you are fault")
                            }
                            MyDialog.destroy();

                            }

                            function FindGrep(){
                            //Clear the find/change preferences.
                            app.findGrepPreferences = NothingEnum.nothing;
                            app.changeGrepPreferences = NothingEnum.nothing;
                            //Set the find options.
                            app.findChangeGrepOptions.includeFootnotes = false;
                            app.findChangeGrepOptions.includeHiddenLayers = false;
                            app.findChangeGrepOptions.includeLockedLayersForFind = false;
                            app.findChangeGrepOptions.includeLockedStoriesForFind = false;
                            app.findChangeGrepOptions.includeMasterPages = false;
                            //find
                            app.findGrepPreferences.findWhat = "[^A-Za-z0-9/.-]+";

                            app.changeGrepPreferences.appliedFont=changeTo;
                            var myFoundItem= app.findGrep ();
                            if(app.changeGrepPreferences.pointSize=app.findGrepPreferences.pointSize){
                            var number=0;
                            number=app.findGrepPreferences.pointSize
                            number=1.3*number;
                            number=app.changeGrepPreferences.pointSize;
                            }
                            app.changeGrepPreferences.underline = true;
                            app.documents.item(0).changeGrep();
                            //Clear the find/change preferences after the search.
                            app.findGrepPreferences = NothingEnum.nothing;
                            app.changeGrepPreferences = NothingEnum.nothing;

                            }
                            • 11. Re: it can not search the text with Grep, what's wronge with my code?
                              Peter Kahrel Adobe Community Professional & MVP
                              you say,
                              >if (app.changeGrepPreferences.pointSize=app.findGrepPreferences.pointSize)

                              but for comparison, you need ==, not =. There's also not much point comparing these two if you haven't set them first. And when you set them like that there's no need to compare them, if you follow me.

                              You need something like this:
                              var myFoundItem = app.findGrep ();
                              
                                 for (var i = 0; i < myFoundItem.length; i++)
                                   if (myFoundItem[i].pointSize == 11 && myFoundItem[i].fontStyle == 'Italic')
                                       // do something


                              The way you've coded the last part of the script and that you use 'myFoundItem' rather than 'myFoundItems' suggest that you don't really understand what app.findGrep () does. Before you continue to tinker with existing scripts you should take some time to learn more about JavaScript. It'll save you much time in the end.

                              Peter
                              • 12. Re: it can not search the text with Grep, what's wronge with my code?
                                robin521 Level 1
                                Hi peter,

                                Again, Thank you very much, I think i must learn more about JavaScript.

                                Robin,
                                Regards