2 Replies Latest reply on May 18, 2015 12:57 AM by koenraad.bats@ds-n.com

    Find/Change by List script in character style subfolders, InDesign CC

    koenraad.bats@ds-n.com Level 1

      I'm trying to replace a text from one Character Style into another Character Style (both in subfolders), using the Find/ChangebyList script in InDesign CC (9.3), but I can't make it work.

      After reading related discussions and after many trial+errors, I ended up with this :

       

      grep{findWhat:"(MRP-Rs.\\s*\\d+\\-)"}{appliedCharacterStyle:app.activeDocument.characterStyleGroups.item("Niet aankomen").characterStyles.item("IndiaDetails")}{changeTo:"$1"}{appliedCharacterStyle:app.activeDocument.characterStyleGroups.item("Extra").characterStyl es.item("MRP")}{includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:true, kanaSensitive:true, widthSensitive:true}//MRP bold 16pt

      But still, nothing happens. So now I got stuck.


      My GREP statement looks ok but I can't get the JavaScript to find Character Style "IndiaDetails" and replace it by "MRP".

       

      I'm new to JavaScript, can anyone help me with this?

        • 1. Re: Find/Change by List script in character style subfolders, InDesign CC
          S Hopkins Adobe Community Professional

          I can see that you are having difficulty. Let me steer you away from using the Find/Change by List script. This script is intended for instances where you have a number of find/changes to perform. Find/Change by List just makes the process more confusing if you only need a simple find/change. For your purpose you only need one find/change. So to simplify the process, script the find/change directly as shown below. Notice in the sample code following how the character styles are referenced as parts of the character style group. (If not part of a character style group, just remove the style group "dot" portion of the reference.) Notice that I named my styles a little different than yours simply because I never use spaces--it's just a personal preference. Hope this helps.

           

          //Find/Change Character Styles

          main();

          function main(){

          var myDocument = app.activeDocument;

          //Define the character styles

          var findCharacterStyle = myDocument.characterStyleGroups.item("Niet").characterStyles.item("IndiaDetails");

          var changeCharacterStyle = myDocument.characterStyleGroups.item("Niet").characterStyles.item("MRPBold_16pt");

          /*define text object that will be target of find/change; expects text selection*/

          var textRef = app.selection[0].texts.item(0);

          //define find change options

          var findChangeOptProps = {caseSensitive:false, wholeWord:false, includeFootnotes:true, includeHiddenLayers:false,

          includeLockedLayersForFind:false,includeLockedStoriesForFind:false, includeMasterPages:false};

          //define the attribute(s) that need to be found/changed

          var findAttrib = {appliedCharacterStyle:findCharacterStyle};

          var changeAttrib = {appliedCharacterStyle:changeCharacterStyle};

          //call the findChange_Attribute function

          var foundSet = findChange_Attribute (textRef,  findAttrib, changeAttrib, findChangeOptProps);

          alert ("" + foundSet.length  + " instances changed");

          }

           

          function findChange_Attribute (textRef,  findAttrib, changeAttrib, findChangeOptProps){

            //initialize text preferences to nothing

              initPrefs();

              //set properties for find text preference

            app.findTextPreferences.properties = findAttrib;

            //set properties for change text preference

              app.changeTextPreferences.properties = changeAttrib;

              //set properties for find/change text options

            app.findChangeTextOptions.properties = findChangeOptProps;

              //perform the change

            var foundSet = textRef.changeText();

            initPrefs();

            return foundSet;

            //initialize text preferences

            function initPrefs () {

            app.findTextPreferences = NothingEnum.NOTHING;

            app.changeTextPreferences = NothingEnum.NOTHING;

            }

          }

          • 2. Re: Find/Change by List script in character style subfolders, InDesign CC
            koenraad.bats@ds-n.com Level 1

            Hi S Hopkins, many thanks for the effort!

             

            But I can't make it work :-(

            InDesign gives me following error :

            Screen Shot 2015-05-18 at 09.44.41.png

            Off course, I changed the names of the desired Character Styles en Style groups on line 11 and 13.

            What did I do wrong?

             

            Actually, I do have a number of find/change instances; I just didn't add them because I expected to be able to fix them as well when this problem would be solved.

            Also, implementing all these instances in a JS would be great. But, as you might have noticed, my knowledge of JS is poor.

            About the use of spaces in styles : I'll change that, I think you're right about it.

            Further on, I am wondering if this JS will change only the desired part of the text (MRP-Rs.\s*\d+\-)?