11 Replies Latest reply on Jul 23, 2014 1:27 AM by Laubender

    Find glyphID for Quotes

    Unique Level 1

      Hi Forum,

       

      I have tried to find the GlypID for quotes, but cannot.

       

      app.findGrepPreferences.findWhat = "\.";

      app.findGrep();

      found = app.findGrep();

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

          if(found[i].length>0) {

      app.select((found[i]));

      alert (found[i].contents.charCodeAt ())

              }}

       

      The above script find and alert GlyphID for all the characters, but when it comes to single quotes or double quotes, it exit.

       

      ESTK error: on selecting quotes: charCodeAt() is not a function.

       

      Can anyone help on this please....

       

      Thanks

        • 1. Re: Find glyphID for Quotes
          Laubender Adobe Community Professional & MVP

          Hello, Unique!

           

          Some of the characters are enumeration values in the light of contents.

           

          Type the following, select it and run the following code from the ESTK (ExtendScript Typekit).

           

          “Hello”

           

          Make sure that you are using the right quotes.

          Code to run:

           

          //Select some text:
          var mySel = app.selection[0];
          var myCharacters = mySel.characters.everyItem().getElements();
          
          for(var n=0;n<myCharacters.length;n++){
              try{
              $.writeln(myCharacters[n].contents.charCodeAt());
              }catch(e){$.writeln(myCharacters[n].contents)};
              };
          

           

          The result would be:

          /*
          DOUBLE_LEFT_QUOTE
          72
          101
          108
          108
          111
          DOUBLE_RIGHT_QUOTE
          */
          

           

          Uwe

          • 2. Re: Re: Find glyphID for Quotes
            Laubender Adobe Community Professional & MVP

            And if we expand this code example a bit to the contents of texts[0] of the single character like that:

             

            //Select some text:
            var mySel = app.selection[0];
            var myCharacters = mySel.characters.everyItem().getElements();
            
            for(var n=0;n<myCharacters.length;n++){
                $.writeln(myCharacters[n].texts[0].contents.charCodeAt());
                };
            
            

             

            We will get the following result:

             

            /*
            8220
            72
            101
            108
            108
            111
            8221
            */
            
            

             

            Uwe

             

            P.S.: Used font: Minion Pro Regular

            • 3. Re: Find glyphID for Quotes
              Laubender Adobe Community Professional & MVP

              Ah. Btw. The result you get is NOT the GlyphID. It's the unicode value.

              Uwe

              • 4. Re: Find glyphID for Quotes
                Laubender Adobe Community Professional & MVP

                See also DOM documentation for Special Characters:

                Adobe InDesign CS6 (8.0) Object Model JS: SpecialCharacters

                 

                Uwe

                • 5. Re: Re: Find glyphID for Quotes
                  Laubender Adobe Community Professional & MVP

                  What can we do we the found results from my answer #2 ?
                  We could use the found and assign it like that:

                   

                  //Change the contents of the first character of a text selection to:
                  //DoubleRightQuote
                  app.selection[0].characters[0].contents = String.fromCharCode(8221);
                  

                   

                  Uwe

                  • 6. Re: Find glyphID for Quotes
                    Unique Level 1

                    Hi Laubender,

                     

                    Thanks for all your hardwork and support.

                     

                    Please bear with me for few minutes.... I just want to get the exact help from you...

                     

                    Please & Please bear with me for the delay..

                    • 7. Re: Find glyphID for Quotes
                      Unique Level 1

                      HI

                      • 8. Re: Find glyphID for Quotes
                        Unique Level 1

                        Hi Laubender,

                         

                         

                        This is what im trying to do.

                         

                         

                        Find special characters inside the document..

                        So what happens is, when the document has any 'quotes' double quotes straight quotes etc., I stops finding and just quites.

                         

                        Just say charCodeAt().is not a function...

                         

                         

                        //Get Alert if the document contents are not the below....

                         

                         

                        try {

                        tf =app.activeDocument.pages.everyItem().textFrames.everyItem().paragraphs.everyItem().lines .everyItem().words.everyItem().characters.everyItem().getElements();

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

                            if(tf[i].contents.charCodeAt()>122

                            && tf[i].contents.charCodeAt()!=8216) //◆//

                            {

                                app.select(tf[i].parentTextFrames[0]);

                                        app.select(tf[i]);

                                alert("Please Check====>Junk characters \r " + tf[i].contents+ " on Page  " + tf[i].parentTextFrames[0].parentPage.name);

                                }

                         

                         

                         

                         

                        Thanks Laubender...

                        • 9. Re: Re: Find glyphID for Quotes
                          Laubender Adobe Community Professional & MVP

                          @Unique – your scope is wrong. You have to look at the contents of texts[0] of the individual character.
                          (I already mentioned this)

                           

                          Getting all characters in all text frames of every page of a doxument is the first step. (You deliberately left out all overset text and all text that is on the pasteboard.)

                           

                          Then in the for loop you target the contents of texts[0] of the character to check for individual charCodeAt() results.

                           

                          I have rewritten and simplified your code a bit (also text frames have characters, so you get them directly from the text frame):

                           

                          myCharacters = app.activeDocument.pages.everyItem().textFrames.everyItem().characters.everyItem().getElements();
                          
                          for (var n = 0; n < myCharacters.length; n++) {
                             
                              var myScope = myCharacters[n].texts[0].contents;
                          
                              if(myScope.charCodeAt()>122 && myScope.charCodeAt()!=8216){
                                 
                                  app.select(myCharacters[n].parentTextFrames[0]);
                                  app.select(myCharacters[n]);
                                  alert(
                                      "Please Check====>Junk characters \r "
                                      + myCharacters[n].texts[0].contents
                                      + " on Page  "
                                      + myCharacters[n].parentTextFrames[0].parentPage.name
                                      );
                          
                                  };
                             
                              };
                          

                           

                          If you alert for myCharacters[n].contents only instead of myCharacters[n].texts[0].contents like I did now, you will get the enumeration number of the special character.

                           

                          Uwe

                          • 10. Re: Re: Find glyphID for Quotes
                            Jump_Over Level 5

                            Hi,

                             

                            Besides all is explained by Uwe already - if your goal is to alert each specialCharacter found in activeDocument - you could run this:

                             

                            var
                            mStories = app.activeDocument.stories.everyItem().getElements(),
                            len = mStories.length, len2,
                            mMsg = "List of specialCharacters found in activeDoc:";
                            
                            while(len-->0){
                              mRes = mStories[len].characters.everyItem().contents.join().match(/[^\,.]{2,}/g);
                              mRes ? len2 = mRes.length : len2 = 0;
                              if (mRes) mMsg += "\nin a story: '" + mStories[len].lines[0].words.everyItem().contents.join(" ") +"...'";
                                   while(len2-->0){
                                   mMsg += "\r\t" + mRes[len2] + ";" ;
                                   }
                              }
                            alert(mMsg);
                            

                             

                            Jarek

                            • 11. Re: Re: Find glyphID for Quotes
                              Laubender Adobe Community Professional & MVP

                              Hi, Jarek!
                              Cool…

                               

                              What I like to mention here: also anchors of anchored objects in texts are "special characters" (value is 65532). Also tables in text. But the scope of Unique's script will leave them out. Value is "13". Also footnotes. Value is "4".

                               

                              Uwe