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

Action script that could automate quote placement via csv file?

Explorer ,
May 14, 2017 May 14, 2017

Copy link to clipboard

Copied

I have a PSD template where I just paste in the quote and author name and save for web, but this is obviously a boring job. Is there any way to automate this process via action or scripting?

I just tried many ways to automate since i have about 100s of quotes to place on template but not find any clues how to do this via scripting... please help me in this regards...
I have a csv file for quotes and Photoshop template
HERE!!!

Thank you in advance...

Capture.PNGCapture2.PNG

TOPICS
Actions and scripting

Views

3.7K

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 ,
May 14, 2017 May 14, 2017

Copy link to clipboard

Copied

Check out Photoshop's Data Driven Graphics feature. You need to define Photoshop variables for the text layers in your template document and create the CSV file to relate the text data to the variables.

JJMack

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
Explorer ,
May 14, 2017 May 14, 2017

Copy link to clipboard

Copied

Ok, I just tried to make data driven graphics option but when upload csv file there is error message popup please see attached?

Capture.PNG

also this will work on Photoshop action to automate this process?

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 ,
May 14, 2017 May 14, 2017

Copy link to clipboard

Copied

Seems the process does not like your CSV file does the first row identify the template layers variable names?

JJMack

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
Explorer ,
May 14, 2017 May 14, 2017

Copy link to clipboard

Copied

Yes I just changed first row to template text name but it this time same error message?

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
Explorer ,
May 14, 2017 May 14, 2017

Copy link to clipboard

Copied

"Data Set 3 was incorrect" it this time, I just put template layer name for quote and author at csv file's top row...

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 ,
May 14, 2017 May 14, 2017

Copy link to clipboard

Copied

Hi mirza5313, perhaps the example downloads in this old topic on Photoshop variables will help:

Re: Data-driven grahics

EDIT: Here is a quick visual:

data.png

This could be a two step process, the first step is to create the layered data set export. The next step would be to create the final PNG or other assets using the image processor pro script, which is running an action for the vertical alignment of the text and re-save the PSD. Easier to do than it sounds!

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
Explorer ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

Sorry for delay, I have tried every thing but csv file is not seems working? 

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
Explorer ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

Still getting the same error could not parse the file contents as a data set

Any clue?

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 ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

mirza5313  – I had some issues with your CSV file.

I added a new row above the existing text, then added column headers (Quote, Attributed). Notice in my screenshot from post #6 that I also used a column header. The first row column header is only a label for use with the variable merge, it is not used as content. I also selected column C and deleted it, there may have been a garbage invisible character in it (the clue being that there is no dataset 3, you should only have 2 columns/datasets).

I used these column header names to define the text replacement name that will be used for the variable.

Then all worked fine:

variable-setup-1.png

variable-setup-2.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
Explorer ,
May 20, 2017 May 20, 2017

Copy link to clipboard

Copied

Thanks Stephen_A_Marsh I just added columns at top of the csv file i.e Quote and Attributed, also new layer with named attributed....

but error message : could not parse the content as a data set?

I know there is some miner mistakes may be adding new layers? I am sorry I am new in this fields of Variables

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 ,
May 20, 2017 May 20, 2017

Copy link to clipboard

Copied

Did you delete column C?… Or conversely, copy column A and B and paste into a new spreadsheet, then save the new spreadsheet as a .csv and try importing that.

You should only have two columns, each with a header and each header is mapped to a layer.

P.S. If you knew which coloured background went with which quote, then you could also use variable images as well (however best to get the text replacing first before getting into image replacements).

Creating data-driven graphics in Photoshop - Adobe Support

Perhaps look into some video tutorials if you are getting lost with text explanations, sometimes a different method of receiving the information will help.

EDIT:

The spreadsheet has column headers named: Quote and Attributed

However the variable names are: Author and Quote

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
Explorer ,
May 20, 2017 May 20, 2017

Copy link to clipboard

Copied

Yes i have copied two columns and past to another file and save as .csv file when import new .csv file error message data set set 3 was incorrect

Capture1.PNG

Capture2.PNG

Capture3.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 ,
May 20, 2017 May 20, 2017

Copy link to clipboard

Copied

I just spent more time looking over your original CSV…

I did not look closely enough before, apologies!

You have quote marks, these are lost when opening into a spreadsheet.

too-many-commas-for-csv-try-tab.png

You also have multiple commas, this will not work with .CSV so you will need to use TAB delimited instead.

You may also need to change the internal double quotes to single quotes, or use single quotes outside and double quotes inside to avoid having two sets of double quotes (hope this makes sense).

Do you know what text encoding and format you are saving the text file into?

And finally, you may need to consider the following:

Prepression: Photoshop – Variables & Leading Double Quote Marks

Due to the “complexity” of your source text file, you are having more issues than may be considered “normal”.

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
Explorer ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Thank you so much Stephen_A_Marsh for your time and efforts this action, so any luck to accomplish this task without Photoshop variables?

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 ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Photoshop, Illustrator and InDesign all offer variables. There are pros/cons with each application, however InDesign would generally be my first choice, then Illustrator and finally Photoshop… However it depends on what is required, sometimes Illustrator may be preferred over InDesign, other times Photoshop would be my preference, then in other situations it would not really matter.

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
Explorer ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

I would prefer Illustrator. IF this can be done via Illustrator

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 ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Yes, this can be done in Illustrator, if you follow the link in my post #15 you will see all of the (early/older) tutorials at my blog for the fantastic VariableImporter script by Vasily Hall for Illustrator. Without this script, you have to mess around with XML input, this script will allow you to import comma/tab separated data and automatically create the required XML on the fly.

That being said, you may prefer to preserver with Photoshop, generally my first choice for text is InDesign, however Illustrator offers the ability to apply complex “appearance” effects which are not possible in InDesign.

.

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
LEGEND ,
Feb 04, 2018 Feb 04, 2018

Copy link to clipboard

Copied

LATEST

I downloaded psd and csv you attached to your first post and tried to use my newest script with them. It was not designed for short 1-line texts, but much bigger with many paragraphs. Anyway I added some part to script that now it makes a loop over slogans & authors from .cvs file, then paste it to text layers and use algorithm from my script to fit it in text area as best as possible to save 28 separate .psd files in subfolder. I didn't have your font so tried with others. With some it works better with others worse, but accuracy is about 85%, so you had a little to change manually font size in about two - six of them:

function font(v1, v2) {

     if (v2 != false) rH = v2 ? v1 * prc = ~~(hgt / (sal = (v1 * tI.autoLeadingAmount / 100))) * sal / hgt : (prc = 1, v1);

     (ref1 = new ActionReference()).putProperty(sTT('property'), sTT(S = ((f = v2 == false) ? 'paragraph' : 'text' ) + 'Style'))

     ref1.putEnumerated(sTT('textLayer'), sTT('ordinal'), sTT('targetEnum')), (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);

     (dsc2 = new ActionDescriptor()).putInteger(sTT('textOverrideFeatureName'), 808460000 + (f ? 4692 : (5400 + (v1 ? 58 : 62))))

     if (!f) {

          dsc2.putInteger(sTT('typeStyleOperationType'), 3), v1 ? dsc2.putUnitDouble(sTT('size'), sTT('pointsUnit'), rH) : dsc2.putBoolean(sTT('autoLeading'), true)

     }

     else {

          dsc2.putDouble(sTT('autoLeadingPercentage'), ~~v1 / 100); for(n = !(i = 0); i < (wlg = ['Word', 'Letter', 'Glyph']).length; i++) {

               for(j = 0; j < (mdm = ['Minimum', 'Desired', 'Maximum']).length; j++) dsc2.putDouble(sTT('justification' + wlg + mdm), !!n); n--

          }

     }

     dsc1.putObject(sTT('to'), sTT(S), dsc2), executeAction(sTT('set'), dsc1, DialogModes.NO); if (v2 != false) return rH

}

function sTT(v) {return stringIDToTypeID(v)} displayDialogs = DialogModes.NO, preferences.typeUnits = TypeUnits.POINTS;

(fle = File(Folder.desktop + '/Quotes.csv')).open('r'), lns = fle.read().split('\n'), fle.close(), Folder(pth = fle.path + '/Slogans').create()

for(z = 0; z < lns.length; z++) {

     QaA = eval(lns.replace(/"(.*)",(.*)/g, '["$1", "$2"]')); (tI = (aL = (lyr = (aD = activeDocument).layers)[0]).textItem).contents = QaA[0]

     lyr[1].textItem.contents = QaA[1], font((wh = [tI.width, tI.height])[Math.abs(+!~~(wh[0] / wh[1]) - 1)] / tI.size * tI.size.as('px') * 1.125)

     font((hgt = tI.height / 72 * (res = aD.resolution)) / (sa = (font(tI.size / Math.sqrt(tI.contents.length/ (function() {return tI.hyphenation = false, font(50, false),

     arr = [], tI.contents = txt = tI.contents.replace(/\r/g, function(_, v) {return arr.push(v), ' '}), font(), aHS = aD.activeHistoryState, tI.kind = TextType.POINTTEXT,

     len = tI.contents.length, aD.activeHistoryState = aHS, len})()))) * (aLA = tI.autoLeadingAmount) / 100) / (((b = aL.bounds)[3] - b[1] ) / sa) * aLA / 72 * res * prc, false)

     i = 0; tI.contents =  txt.replace(/ /g, function(_, v) {return v == arr ? (i++, '\r' ) : ' '}) font(tI.size * Math.sqrt((r = hgt / (tI.size * tI.autoLeadingAmount / 100)) / (r + i)), true)

     font(tI.autoLeadingAmount * (!((function(){return len1 = tI.contents.length, aHS = aD.activeHistoryState, tI.kind = TextType.POINTTEXT, r = tI.contents.match(/\r|$/g).length,

     R = (con = len1 != len2 = tI.contents.length) ? tI.contents.match(/(.*)(?=\r+$)/)[1].length - 1 : (hgt / 72 * res) / (tI.size.as('px') * (tI.autoLeadingAmount / 100) * r),

     aD.activeHistoryState = aHS, con})()) ? R : ((put = tI.contents.slice(R).match(/\r/g)) ? r / (r + put.length + 1) : len2 / len1)), false), aD.saveAs(File(pth + '/' + (z + 1)))

}

Original code without changed values (that works for bigger texts): How to make text fit inside a paragraph bounding box

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