• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Script to change text layers contents in photoshop

Community Beginner ,
Mar 17, 2019 Mar 17, 2019

Copy link to clipboard

Copied

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.

TOPICS
Actions and scripting

Views

11.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Mar 19, 2019 Mar 19, 2019

Copy link to clipboard

Copied

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

Because of there are too much possibilities.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 20, 2019 Mar 20, 2019

Copy link to clipboard

Copied

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.Capture.PNG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 20, 2019 Mar 20, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 21, 2019 Mar 21, 2019

Copy link to clipboard

Copied

Hi,

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

It may help me in my works>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 09, 2022 Apr 09, 2022

Copy link to clipboard

Copied

Hi thanks 

I need your help
Because this layer is opened to the document, the text can be replaced
this js code ,if using c# how to write this code? thanks
runMenuItem(stringIDToTypeID('placedLayerEditContents')) 
 
If the layer is a picture, how do I replace it? Using c#

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 09, 2022 Apr 09, 2022

Copy link to clipboard

Copied

LATEST

23.pngusing c# com interface create a selection region and replace text contents

thanks  a lot

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 20, 2019 Mar 20, 2019

Copy link to clipboard

Copied

If you are using windows this C# program should work

N.B. There isn't much error checking though.

It prompts for the Excel file and expects the document open in Photoshop.

using System;

using System.Windows.Forms;

namespace CreateExcel

{

    class Program

    {

        [STAThread]

        static void Main(string[] args)

        {

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "Excel Worksheets|*.xl*";

            dlg.Multiselect = false;

            string name;

            if (dlg.ShowDialog() == DialogResult.OK)

            {

                name = dlg.FileName;

            }

            else

            {

                return;

            }

             var excelType = Type.GetTypeFromProgID("Excel.Application");

            if (excelType == null) return;

            dynamic excel = Activator.CreateInstance(excelType);

            excel.Visible = false;

            excel.Workbooks.Open(name);

            string Location = excel.Cells(1, 1).Value;

            string Age = excel.Cells(2, 1).Value;

            string Address = excel.Cells(3, 1).Value;

            string Name = excel.Cells(4, 1).Value;

            excel.Quit();

            dynamic app = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));

            if (app.Documents.Count == 0) return;

            app.ActiveDocument.ActiveLayer = app.ActiveDocument.ArtLayers.GetByName("Location");

            app.ActiveDocument.ActiveLayer.TextItem.Contents = Location;

            app.ActiveDocument.ActiveLayer = app.ActiveDocument.ArtLayers.GetByName("Age");

            app.ActiveDocument.ActiveLayer.TextItem.Contents = Age;

            app.ActiveDocument.ActiveLayer = app.ActiveDocument.ArtLayers.GetByName("Address");

            app.ActiveDocument.ActiveLayer.TextItem.Contents = Address;

            app.ActiveDocument.ActiveLayer = app.ActiveDocument.ArtLayers.GetByName("Name");

            app.ActiveDocument.ActiveLayer.TextItem.Contents = Name;

        }

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 21, 2019 Mar 21, 2019

Copy link to clipboard

Copied

Hi,

thanks for the script,
acutuall im using mac, i will try to see if the script works on mac also.

The problem with the script is,

it will find the layers name in photoshop then change the text content,
what if i have more text layers with different name.

Is there a way to tell the script, the first row on the excel file , goes in the first text layer in photoshop>

the 2nd row to the 2nd text layer,
and it goes on like this.

thanks a lot

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 21, 2019 Mar 21, 2019

Copy link to clipboard

Copied

That code needs to be complied  (Using Visual Studio) into an exe file so it will not work with a Mac. It is Windows only.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines