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

How to read .xlsx data and push to array in .js script for photoshop

Community Beginner ,
Jul 29, 2022 Jul 29, 2022

I am building some automation for work and have reached my limit of comfortable knowlege in scripting.

 

I have a. .xlsx file where:

column A1 thru A20 represents a design we have created.

column B1 thru B20 contains lists of color background templates for each design in column A:

templateArray.jpgexpand image

I also have a folder with .png files whos file names exactly match the names given in column A.

 

My script uses photoshop batching to open one file (eg: XY-111.png) at a time in that folder,

place that .png on all of the templates (eg: Temp1, Temp3, Temp5) and save each as a .jpg (using a different script).

placementCode.jpgexpand image

The above code WORKS, but instead of

excelArray.push(Temp1, Temp2, Temp3)

I want to push the data in column B to the array ONLY if app.documents[0] matches column A.

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

The code:

#target photoshop

var Temp1 = "/Temp1.psd"
var Temp2 = "/Temp2.psd"
var Temp3 = "/Temp3.psd"
var Temp4 = "/Temp4.psd"
var Temp5 = "/Temp5.psd"
var Temp6 = "/Temp6.psd"
var Temp7 = "/Temp7.psd"
var Temp8 = "/Temp8.psd"
var Temp9 = "/Temp9.psd"
var Temp10 = "/Temp10.psd"

var picForSim = app.documents[0];

var excelArray = [];

excelArray.push(Temp1, Temp2, Temp3);

for (var i = 0; i < excelArray.length; i++){
if (picForSim.name.charAt(0) === "W"){
//alert(excelArray[i])
app.open(new File(excelArray[i]));
app.doAction(("WGARMENTS-ArtPlace"), ("ProductActions.ATN"))
} else {
//alert(excelArray[i])
app.open(new File(excelArray[i]));
app.doAction(("GARMENTS-ArtPlace"), ("ProductActions.ATN"))
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

I took a node.js tutorial but i'm having some trouble connecting the dots.

any help would be appreciated!

TOPICS
Actions and scripting , Windows
736
Translate
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 ,
Aug 02, 2022 Aug 02, 2022

I don’t quite follow. 

If you want to include a conditional you can use an if-clause: 

if (app.documents[0].fullName == excelArray[i]) {…

(As I am not sure what exactly you mean the terms in this example may be wrong,) 

Translate
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 ,
Aug 02, 2022 Aug 02, 2022
LATEST

It should run like this: WXY-111.png is open in photoshop, Cell A1 says WXY-111, excelArray is B1. BUT if WXY-222.png is open in photoshop, Cell A2 says WXY-222 so, excelArray is B2. I want to push the contents of one cell in column B to excelArray, if the adjacent cell in column A is the same as the .png open in photoshop. My example in this post is a dummy. There will be 800 possible urls when I'm done. also, column B isnt going to be four items every time, it could be any combination of undetermined templates from the 800 possible. Each time a .PNG is processed and exported through the actions, it makes 4 .JPEG images. I don't want to make 3,200 .JPEGs for each .PNG... I just want to make the ones I need at a given time. I can't just match picForSim to one of the possible .PSD templates, it needs to go on an undetermined selection of them... I will make that selection on an excel sheet and save it (in whatever format is easiest)... I just don't know how to get the information from the excel sheet to excelArray. If I manually write in the template variables (Temp1, Temp2 for example) it works fine... so I know the basis for this works... I just need to get this one thing working (replace the empty array with an array listed in some kind of file) but it HAS to be the array associated with the picForSim (the .PNG in the zeroth index of the photoshop application) or else I wont apply the correct design to the correct selection of templates.

Translate
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