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

Help .... newb question. CSV file and Hex fill script

New Here ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

Hey guys,

i have a daunting task infront front of me and I am thinking a smarter way would be a script. Problem I don’t code.

I need to create a whack of hex swatch png files (2000px by 2000px - 72dpi) for a project. I have a bunch of upc codes, and their hex values separated in a csv table and I need to use the hex value to fill the square and save the file using both fields as part of the filename.

so so I have a the 12 digit upc say 057896543001 and the hex value for that of say 325647 ...... I would need a coloured square png with the fill color of 325647 and a file name of 057896543001_325647.png

manually it is taking a minute or so for each file ..... any direction or help would be greatly appreciated In building a script to automate this process.

cheers,

james

TOPICS
Actions and scripting

Views

289

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
Guide ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

LATEST

You could try this, it needs a csv file in the format:-

upc,hex

057896543001,325647

057856543001,ff0000

957896543001,ffff00

#target photoshop;

main();

function main(){

var csvFile = File.openDialog("Open Comma-delimited File","comma-delimited(*.csv):*.csv;");

if(csvFile == null) return;

var outputFolder = Folder.selectDialog( "Please select output folder");

if(outputFolder == null ) return;

csvFile.open("r");

var data = csvFile.read().split("\n");

csvFile.close();

app.preferences.rulerUnits = Units.PIXELS; 

app.preferences.typeUnits = TypeUnits.PIXELS; 

var doc = app.documents.add(2000, 2000, 72, null, NewDocumentMode.RGB, DocumentFill.WHITE);

for(var a in data){

if(data.length < 12) continue;

var line = data.split(",");

if(line[0].replace(/^\s+|\s+$/g,'').match(/^[a-zA-Z]/)) continue;

var upc = line[0].replace(/^\s+|\s+$/g,'');

var hex = line[1].replace(/^\s+|\s+$/g,'');

var saveFile = File(outputFolder + "/" + upc + "_" + hex + ".png");

var FillColour = new SolidColor;

FillColour.rgb.hexValue = hex;

activeDocument.selection.selectAll();

activeDocument.selection.fill(FillColour);

activeDocument.selection.deselect();

SavePNG(saveFile);

    }

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

};

function SavePNG(saveFile){

    pngSaveOptions = new PNGSaveOptions();

activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);

}

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