18 Replies Latest reply on Feb 4, 2018 9:33 PM by Kukurykus

    Action script that could automate quote placement via csv file?

    mirza5313 Level 1

      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

        • 1. Re: Action script that could automate quote placement via csv file?
          JJMack Most Valuable Participant

          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.

          • 2. Re: Action script that could automate quote placement via csv file?
            mirza5313 Level 1

            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?

            • 3. Re: Action script that could automate quote placement via csv file?
              JJMack Most Valuable Participant

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

              • 4. Re: Action script that could automate quote placement via csv file?
                mirza5313 Level 1

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

                • 5. Re: Action script that could automate quote placement via csv file?
                  mirza5313 Level 1

                  "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

                  • 6. Re: Action script that could automate quote placement via csv file?
                    Stephen_A_Marsh Adobe Community Professional

                    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!

                    • 7. Re: Action script that could automate quote placement via csv file?
                      mirza5313 Level 1

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

                      • 8. Re: Action script that could automate quote placement via csv file?
                        mirza5313 Level 1

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

                         

                        Any clue?

                        Capture.PNG

                        • 9. Re: Action script that could automate quote placement via csv file?
                          Stephen_A_Marsh Adobe Community Professional

                          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

                          • 10. Re: Action script that could automate quote placement via csv file?
                            mirza5313 Level 1

                            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

                            • 11. Re: Action script that could automate quote placement via csv file?
                              Stephen_A_Marsh Adobe Community Professional

                              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

                              • 12. Re: Action script that could automate quote placement via csv file?
                                mirza5313 Level 1

                                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

                                • 13. Re: Action script that could automate quote placement via csv file?
                                  Stephen_A_Marsh Adobe Community Professional

                                  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”.

                                  • 14. Re: Action script that could automate quote placement via csv file?
                                    mirza5313 Level 1

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

                                    • 15. Re: Action script that could automate quote placement via csv file?
                                      Stephen_A_Marsh Adobe Community Professional

                                      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.

                                      • 16. Re: Action script that could automate quote placement via csv file?
                                        mirza5313 Level 1

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

                                        • 17. Re: Action script that could automate quote placement via csv file?
                                          Stephen_A_Marsh Adobe Community Professional

                                          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.

                                           

                                          .

                                          • 18. Re: Action script that could automate quote placement via csv file?
                                            Kukurykus Adobe Community Professional

                                            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[i] + mdm[j]), !!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[z].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] ? (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