5 Replies Latest reply on Aug 27, 2014 4:38 AM by elmagnifico

    A script for replacing texts only in selected layer?

    elmagnifico

      Hi all,

      I have an illustrator document which has many text layers. I have found the script below that replace a text with another one in the document;

       

      var doc = app.activeDocument;

      var myTextFrames = doc.textFrames;

       

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

      var myTF_ByI = myTextFrames[i];

      var str = myTF_ByI.contents

      var res = str.replace("word1", "word2");

      myTF_ByI.contents = res

      }


      However, there is one problem that the script also replaces the text in other layers even though they are hidden or locked. Could you help me adjust this script to be effective only for the selected or unhidden layer?

       

      Cheers,

      Akin