Skip to main content
Alv14
Known Participant
March 17, 2019
Frage

Script to change text layers contents in photoshop

  • March 17, 2019
  • 3 Antworten
  • 14550 Ansichten

Hi Everybody,

I have a photoshop file with existing text layers,
and i have a word or excel document.

I would like to know if its possible to make a script to copy from the word/excel and replace the text in each photoshop layers.

OR

i copy a paragraph from the word/excel and as i click on a text layers and run a script to change the text content.

Thanks a lot.

Dieses Thema wurde für Antworten geschlossen.

3 Antworten

Participant
April 5, 2019

Allrighty.

I made a script that loads a .txt file and split it into an array
Then the script finds all Artborads/Groups and loops thru all textlayers
and fill the text content with the array.


https://www.dropbox.com/s/lur2xo8o6mr4qr9/from-txt-to-psd.zip?dl=0https://www.dropbox.com/s/lur2xo8o6mr4qr9/from-txt-to-psd.zip?dl=0

// to get line breaks in the text file you need to insert  ( %0D%0A  ).
Im line one  %0D%0A i am line tow resoults in

Im line one
I am line tow

Participant
April 5, 2019

I have a simple js script you can use.

it runs thru all the layers in your photoshop file, if the layer is a text file

it uses the content of the array.  It is far from perfect but it works.

Save the script as yourfilename.js 
and run it in photoshop



#target photoshop;    //array of what ever you need - but as many items in the array as text layers in the photoshop file var itemsAry=['Spain','lardtub','100','grandma on fire', 'nutbag','null','1000000'];  var layers = app.activeDocument.layers;   for (var i =0; i<layers.length; i++) {        if (layers.kind == "LayerKind.TEXT") {                  layers.textItem.contents=itemsAry     }  }



js and photshop test file for download



https://www.dropbox.com/s/26lhgfha7jhoco5/fucj-year-psd-text.zip?dl=0

pixxxelschubser
Community Expert
Community Expert
March 19, 2019

Please show something (screenshots or example *.psd + *.word/excel)

Because of there are too much possibilities.

Alv14
Alv14Autor
Known Participant
March 20, 2019

Hi,

Thanks for your reply,
below is a small exemple of what i want to do.

on the left is the excel file and on the right the PSD.
As you can see the psd has 4 text layers and 4 rows in the excel file.

Instead of going in the excel copy the text, then double click on the text layer in photoshop and paste to change the text,

I want to know if any script can be done to do that.

Alv14
Alv14Autor
Known Participant
March 21, 2019

Thank you for your example.

Yes. it is scriptable. But it depends the layers hierarchie.

Only one note: based on your example - IMO this should be the better way to go: Creating data-driven graphics in Photoshop

If so, have fun


Hi,

thanks for your help, i will try to learn the variable.

It may help me in my works>