1 Reply Latest reply on Aug 26, 2016 1:01 AM by SuperMerlin

    Load a list of words in individual text layers

    Dario de Judicibus Level 1

      Is there a way to load a list of words from a text file, for example

       

      Rome

      Berlin

      London

      Madrid

      ...

       

      and create a text layer for EACH word in a Photoshop document?

        • 1. Re: Load a list of words in individual text layers
          SuperMerlin Level 5

          This example requires that a document is open in Photoshop.

          The script will prompt for a text file containing the names.

          All the names will be in the same place but on seperate layers.

           

          #target photoshop;
          if(documents.length) main();
          function main(){
          var txtFile = File.openDialog("Please select TEXT.","TXT File:*.txt");
          var Names = [];
          if(txtFile == null) return;
          txtFile.open('r');
          var data = txtFile.read();
          txtFile.close();
          data = data.split('\n');
          for (var a in data){
              var line = data[a].replace(/^\s+|\s+$/g);
              if(line.length >3) Names.push(line);
              }
          for(var n in Names){
              createTextLayer(Names[n]);
              }
          };
          function createTextLayer(layerName) {  
          var startRulerUnits = app.preferences.rulerUnits;
          app.preferences.rulerUnits = Units.PIXELS;
          var thisLayer = activeDocument.artLayers.add(); 
          thisLayer.kind = LayerKind.TEXT; 
          thisLayer.name = layerName; 
          var textProperty = thisLayer.textItem; 
          textProperty.kind = TextType.POINTTEXT;
          //Font Size
          textProperty.size = 10; 
          textProperty.font = "Arial"; 
          var newColor = new SolidColor(); 
          //Font Colour
          newColor.rgb.red = 0; 
          newColor.rgb.green = 0; 
          newColor.rgb.blue = 0; 
          textProperty.color = newColor; 
          textProperty.position = new Array( 100,100);
          thisLayer.blendMode = BlendMode.NORMAL; 
          thisLayer.opacity = 100; 
          textProperty.contents = layerName; 
          app.preferences.rulerUnits=startRulerUnits;
          }; 
          
          
          1 person found this helpful