How to open files from CSV

New Here ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

I have a test script I wrote to open illustrator files, add some text and then save them.

 

What I want to do is get a list of filenames, text info, and filename to save to, from a CSV. My example code works I just don't know how to import the CSV into the const filenames, const templatefiles, const personalisation etc

 

Thanks for any insight you guys can give 🙂

 

#target Illustrator

const filenames = ["f1", "f2","f3"]
const templatefiles = ["TEMPLATE_CUS_PAD40_03.ai", "TEMPLATE_CUS_PAD40_03.ai","TEMPLATE_CUS_PAD40_03.ai"];
const personalistation = ["personalisation text 1", "personalisation BLAH 2","personalisation  MEH 3"];
const filepath = 'E:/Products/ALL FILES/';

function ProcessFiles()
{
	for(processedfiles = 0; processedfiles < 3; processedfiles++){
		File = app.open(new  File(filepath + templatefiles[processedfiles]));
		
		var doc = app.activeDocument;
	    var text = app.activeDocument.layers[0].textFrames.pointText([0, 0]); 

		app.coordinateSystem  = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;

		text.textRange.characterAttributes.size = 14.5;
		text.textRange.characterAttributes.textFont = app.textFonts["SegoeScript-Bold"];
        	text.contents = personalistation[processedfiles];
		text.position = [0,75];
		
		var fname = filenames[processedfiles];
        doc.saveAs(new File("E:/Products/scriptoutput/" + fname));
	};	
};
 
ProcessFiles();

 

 

TOPICS
Import and export , Scripting

Views

49

Likes

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 Professional ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

LATEST

You can use a CSV parser. In the past I used one such snippet I found at the following blog and it worked for my purpose

https://www.bennadel.com/blog/1504-ask-ben-parsing-csv-strings-with-javascript-exec-regular-expressi...

Open your CSV file and read it line by line in your JS and then pass each line of data to the method mentioned in the blog and you should recieve the list of values in an array.

You can search other parsers as well.

P.S.:- Be warned that looking at samples of modern JS won't work in extendscript for obvious reasons

-Manan

Likes

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