6 Replies Latest reply on Feb 17, 2016 2:21 AM by LeoMari

    Find text change to Glyph

    patrickbcm

      Hello

       

      I 'am looking for a script that find text and change it to a glyph with a color for example red.

      Something like this:

      Find #H and change it to glyph unicode 2665 with font ITC Zapf Dingbats Std and color name Red.

      Find #R and change it to glyph unicode 2666 with font ITC Zapf Dingbats Std and color name Red.

      Find #K and change it to glyph unicode 2663 with font ITC Zapf Dingbats Std and color name Black.

      Find #S and change it to glyph unicode 2660 with font ITC Zapf Dingbats Std and color name Black.

      I use Indesign CS6 on mac.

       

      Kind regards

      Patrick

        • 1. Re: Find text change to Glyph
          LeoMari Level 2

          You can try something like:

           

          var myDoc = app.documents[0]
          
          
           //
              if (myDoc.paragraphStyles.itemByName("Paragraph Style Name").isValid){
                  
                  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.findGrepPreferences = NothingEnum.nothing;
                  app.changeGrepPreferences = NothingEnum.nothing;
          
          
                  app.findGrepPreferences.findWhat = "a";  //character
                  app.findGrepPreferences.appliedColor = "NameColor";
                  app.findGrepPreferences.appliedParagraphStyle = "Paragraph Style Name"; 
                  app.findGrepPreferences.appliedFont = "Name Font";
                  app.findGrepPreferences.underline  = true;
                  app.findGrepPreferences.position = Position.SUPERSCRIPT;
                  app.changeGrepPreferences.changeTo = "ª";  //character substitute
                  app.changeGrepPreferences.appliedColor = "NameColor";
                  app.changeGrepPreferences.appliedCharacterStyle = "Paragraph Style Name";
                  app.activeDocument.changeGrep();
          
          
                  app.findGrepPreferences = NothingEnum.nothing;
                  app.changeGrepPreferences = NothingEnum.nothing;
              }   
          
          
          
          
          
          
          
          
          

           

          Hug!

          • 2. Re: Find text change to Glyph
            patrickbcm Level 1

            Hello LeoMari

             

            When i fill in the script i get a error of a color.

             

            var myDoc = app.documents[0] 

             

             

            // 

                if (myDoc.paragraphStyles.itemByName("plt").isValid){ 

                     

                    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.findGrepPreferences = NothingEnum.nothing; 

                    app.changeGrepPreferences = NothingEnum.nothing; 

             

             

                    app.findGrepPreferences.findWhat = "#H";  //character 

                    app.findGrepPreferences.appliedColor = "Zwart"; 

                    app.findGrepPreferences.appliedParagraphStyle = "plt";  

                    app.findGrepPreferences.appliedFont = "ITC Zapf Dingbats"; 

                    app.findGrepPreferences.underline  = true; 

                    app.findGrepPreferences.position = Position.SUPERSCRIPT; 

                    app.changeGrepPreferences.changeTo = "2660";  //character substitute 

                    app.changeGrepPreferences.appliedColor = "kaartkleur"; 

                    app.changeGrepPreferences.appliedCharacterStyle = "harten"; 

                    app.activeDocument.changeGrep(); 

             

             

                    app.findGrepPreferences = NothingEnum.nothing; 

                    app.changeGrepPreferences = NothingEnum.nothing; 

                }

            Schermafbeelding 2016-02-17 om 08.43.26.png

            it must be like this

            Schermafbeelding 2016-02-17 om 08.29.35.png

            • 3. Re: Find text change to Glyph
              Laubender Adobe Community Professional & MVP

              Hi Patrick,

              instead of appliedColor—there is no property with this name—try fillColor .

              Did not test, if fillColor will work in this case, if a String, the name of the color, is assigned.

               

              Uwe

              • 4. Re: Find text change to Glyph
                patrickbcm Level 1

                I get the same problem. And when i put that line out. I get no error but nothing is changed.

                 

                I use now standard findChangeByList with this in the txt

                text{findWhat:"#H"}{appliedCharacterStyle:"harten"}{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}Find all dash-dash and replace with an em dash.
                text{findWhat:"#H"}{changeTo:"<2665>"}{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}Find all space-dash-space and replace with an en dash.

                 

                 

                text{findWhat:"#K"}{appliedCharacterStyle:"klaver"}{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}Find all dash-dash and replace with an em dash.
                text{findWhat:"#K"}{changeTo:"<2663>"}{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}Find all space-dash-space and replace with an en dash.

                 

                 

                text{findWhat:"#S"}{appliedCharacterStyle:"schoppen"}{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}Find all dash-dash and replace with an em dash.
                text{findWhat:"#S"}{changeTo:"<2660>"}{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}Find all space-dash-space and replace with an en dash.

                 

                 

                text{findWhat:"#R"}{appliedCharacterStyle:"ruiten"}{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}Find all dash-dash and replace with an em dash.
                text{findWhat:"#R"}{changeTo:"<2666>"}{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

                Find all space-dash-space and replace with an en dash.

                 

                But when i use this indesign is quitting when i use the script in document en when i select all.

                When i do it for example in 20 rows it will work fine.

                • 5. Re: Find text change to Glyph
                  Peter Kahrel Adobe Community Professional & MVP

                  Patrick,

                   

                  <2600> etc. are the Unicode values of the suit symbols, not the glyph IDs. And you confused the text and the Grep notations for Unicode characters: <2600> is used in text searches and replacements, \x{2600} in Grep. To change the symbols and apply the character styles, you can use a script like this:

                   

                  app.findGrepPreferences = app.changeGrepPreferences = null;
                  
                  function kleur (afkorting, unicode, stijl) {
                    app.findGrepPreferences.findWhat = afkorting;
                    app.changeGrepPreferences.changeTo = unicode;
                    app.changeGrepPreferences.appliedCharacterStyle = stijl;
                    app.activeDocument.changeGrep()
                  }
                  
                  kleur ('#S', '\\x{2660}', 'schoppen');
                  kleur ('#H', '\\x{2665}', 'harten');
                  kleur ('#R', '\\x{2666}', 'ruiten');
                  kleur ('#K', '\\x{2663}', 'klaveren');
                  

                   

                  Since there's nothing GREPpy what you're looking for you could use find/changeText too, but grep replacements tend to be quicker than text replacements.

                   

                  Peter

                  • 6. Re: Find text change to Glyph
                    LeoMari Level 2

                    app.findGrepPreferences.fillColor = "kaartkleur";

                    Invalid value for set property 'fillcolor'. Expected String, swatch or nothingEnum enumerator, but received "kaartkleur".

                    while i am give like this:

                    app.findGrepPreferences.fillColor =app.activeDocument.colors.item( "kaartkleur");

                    (or)

                    app.findGrepPreferences.fillColor =app.activeDocument.swatches.item( "kaartkleur");