2 Replies Latest reply on Oct 7, 2013 3:20 PM by cramik

    Replace textmarker with number (1, 2, 3 ...)


      I wonder if there's a way to work with variables in Indesign.

      I've got a indesign file that contains multiple occurences of "##" (as placeholder-text).

      I want to replace the first occurence with the number 1, the second with the number 2 and so on...

      Is there a way this can be done with scripting in Indesign.


      (The way i do this now is by exporting the file to xtag-text and then use a php-script to replace the markers in the tagged file)

        • 1. Re: Replace textmarker with number (1, 2, 3 ...)
          Jump_Over Level 5



          Try this as a .jsx script to run from ESTK or ID Script Panel:


          #target indesign
              placeholder = "##",
              mFound, len, start = 1;
              if (app.selection[0] &&  (app.selection[0] instanceof "Text Frame" || app.selection[0].hasOwnProperty ("baseline") ) )
                  var mStory = app.selection[0].parentStory;
              else { alert("Select target textFrame or some part of target text\rand try again!"); exit();}
          app.findTextPreferences = null;
          app.findTextPreferences.findWhat = placeholder;
          mFound = mStory.findText();
          len = mFound.length;
          while (len-->0)
              mFound[len].contents = (len + start).toString();


          - placeholder is a string to find; start is a value of first number to replace.

          - some part of text or textFrame should be selected.



          • 2. Re: Replace textmarker with number (1, 2, 3 ...)
            cramik Level 1

            That's exactly wat i needed. This opens a world of possibilities...