2 Replies Latest reply on Jan 23, 2017 3:00 AM by subieguy2

    move textFrame to specific layer

    subieguy2 Level 1

      So I am wanting to search through the entire document for all text frames that contain an underscore. If the text frame does include an underscore I am wanting to move that text frame to a specific layer called "Hypertext". Then I want to remove the underscore from that text frame. So in my code below I have it doing everything I have mentioned except I don't know how to get it to move to a specific layer. Any help would be appreciated!

       

      #target illustrator
      var doc = app.activeDocument;
      var allText = doc.textFrames;
      
      
      var searchString = /_/g;
      var replaceString = " ";
      
      
      for (var i = 0; i < allText.length; i++) {
          var thisTextFrame = allText[i];
          var newString = thisTextFrame.contents.replace(searchString, replaceString);
          if (newString != thisTextFrame.contents) {
              //alert("Contains an underscore");
              allText[i].move("Hypertext");
              thisTextFrame.contents = newString;
          }
      }
      
        • 1. Re: move textFrame to specific layer
          Silly-V Adobe Community Professional

          You can just use allText[i].move(targetLayer, ElementPlacement.PLACEATEND)

          But you may want to go through the loop backwards in case the moving changes the length property of the collection of text frames.

          1 person found this helpful
          • 2. Re: move textFrame to specific layer
            subieguy2 Level 1

            Works perfect! Thank you! Here is the final code with the targetLayer variable....

            #target illustrator
            var doc = app.activeDocument;
            var allText = doc.textFrames;
            
            
            var searchString = /_/g;
            var replaceString = " ";
            
            
            var targetLayer = doc.layers.getByName("Hypertext");
            
            
            for (var i = allText.length - 1; i >= 0; i--) {
                var thisTextFrame = allText[i];
                var newString = thisTextFrame.contents.replace(searchString, replaceString);
                if (newString != thisTextFrame.contents) {
                    //alert("Contains an underscore");
                    allText[i].move(targetLayer, ElementPlacement.PLACEATEND);
                    thisTextFrame.contents = newString;
                }
            }