Skip to main content
Participant
August 5, 2022
Question

Does anyone have a script that utilizes a CSV to create text layers?

  • August 5, 2022
  • 3 replies
  • 4104 views

I work in Post-Production and am trying to streamline my legal line creation process using a CSV.  I have very limited Javascript experience and am hopeful that someone has a method to auto create text layers using a CSV OR could help point me in the right direction.

 

Thank you

This topic has been closed for replies.

3 replies

Legend
October 18, 2022

This reads line by line rather than use a CSVfile, but it does what you ask.

#target photoshop

addText();

function addText(){
    if(documents.length > 0){
        var originalDialogMode = app.displayDialogs;
        app.displayDialogs = DialogModes.ERROR;
        var originalRulerUnits = preferences.rulerUnits;
        preferences.rulerUnits = Units.PIXELS;
        try{
            var testFile = new File('~/Desktop').openDlg('Select import file', '*.txt');
            if(testFile != null){
                testFile.open('r');
                var textLine = testFile.readln();
                var docRef = activeDocument;
                var LayerRef = null;
                var TextRef = null;
                var pos = 200;
                while(textLine != ''){ //read in text one line at a time
                    LayerRef = docRef.artLayers.add();
                    LayerRef.kind = LayerKind.TEXT;
                    TextRef = LayerRef.textItem;
                    TextRef.contents  = textLine;
                    //optional text styling, can be customized to suit
                    pos = pos + 50;
                    TextRef.position = new Array(pos, pos);
                    preferences.rulerUnits = Units.POINTS;
                    TextRef.size = 24;
                    TextRef.useAutoLeading = false;
                    TextRef.leading = 24;
                    TextRef.font = 'Calibri-Bold';
                    TextRef.justification = Justification.CENTER;
                    TextRef.autoKerning = AutoKernType.METRICS;
                    //end optional text styling
                    textLine = testFile.readln();
                    }
                testFile.close();
                }
            }
        catch(e){
            alert(e + e.line);
            preferences.rulerUnits = originalRulerUnits;
            app.displayDialogs = originalDialogMode;
            return;
            }
        preferences.rulerUnits = originalRulerUnits;
        app.displayDialogs = originalDialogMode;
        }
    else{
        alert('You must have a document open to run this script.');
        return;
        }
    return;
    }
Stephen Marsh
Community Expert
Community Expert
October 18, 2022

@Lumigraphics – Thank you, I'll see if I can make something from what you have offered.

willcampbell7
Legend
August 6, 2022

I have a number of scripts that do things with CSV data, for Photoshop and other apps, but not any published yet that do precisely what you describe. It is certainly possible. The one Photoshop script of mine that is close is described in this video: https://youtu.be/zsaVUHEi6X0

I have two other scripts in progress at this time for some clients that work on multiple text layers from multiple CSV columns. Nothing that creates the layer, but that's not a big deal. The scripts I've made the clients had the layer already because they wanted to style it with effects. That's a good reason to have a layer exist already. I do custom scripts for hire to exact client needs. If interested message me through my website http://www.marspremedia.com/contact/

 

William Campbell
Participant
August 6, 2022

Wow, this is really cool for me, I have been watching your tutorials all week.  Thank you for your response!  I'll keep trying with your tutorials for now. 

willcampbell7
Legend
August 7, 2022

That's great! Thanks for watching. Is this a script you want to write yourself? And just need some help? I don't usually post entire scripts because some of mine are thousands of lines, but I'll be happy to post code for a function that parses CSV if you want. Or other specifics tasks. Making a layer isn't too difficult. I think my script tutorial #6 video has some about that. But if not enough, we're always ready to answer questions.

 

William Campbell
Stephen Marsh
Community Expert
Community Expert
August 5, 2022

Photoshop has a built in Variable feature to populate existing text placeholder layers with content from a comma or tab delimited text file.

 

Otherwise, yes, a script can read from the .csv and create a text layer and content.

 

It would be helpful if you could provide sample files or before and after screenshots to illustrate, as there are more questions than answers at the moment.

Participant
August 6, 2022

I know how to use a CSV to replace exisiting variables.  What I am hoping to accomplish is have a blank canvas with no layers, have photoshop read a CSV and create multiple text layers for me to export.  Rather than me creating a new layer and then copy/pasting each new legal line from a word document. 

Participant
August 6, 2022

Attached images