2 Replies Latest reply on Feb 8, 2015 6:39 AM by MRaj01

    replace text with images

    MRaj01

      Hi,

      I'm using a script found here, to replace @equ001.pdf@ with the corresponding image, same for eq002 etc.
      This script works more or less ok for me.

      Sometimes, it removes some image names without replacing the image, sometimes it was leaving some "@" here and there.

      Sometimes, it's giving me an error on the "place image" code, saying it cannot find the image, giving it's path ending with the grep expression $2 and doesn't work at all.

      Sometimes it does part of the job, stops, gives the same error as above, and continues to work when I click ok.

      Today, it didn't worked on a document. I copied the text to work on into a new InDesign document an there, it worked (but in two times).

       

      Is there any other way of doing this ?

       

      if(app.documents.length != 0){

          var myFolder = Folder.selectDialog ('Choose a folder with images');

          if(myFolder != null){

              // reset the Find/Change dialog

              app.findGrepPreferences = app.changeGrepPreferences = null;

              // formulate a grep search string

              app.findGrepPreferences.findWhat = '@.+?@';

              // find all occurrence, last one first

              f = app.activeDocument.findGrep (true);

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

                  // construct file name

                  name = f[i].contents.replace (/@/g, '');

                 

                  // place the image

                  var placedObjects = f[i].insertionPoints[0].place (File (myFolder.fsName + '/' + name));

              }

          // delete all @??@ codes

          app.activeDocument.changeGrep();

          }

      }

      else{

         alert('Please open a document and try again.');

      }