Reply To: How to create a series of texte frame using values from txt file

#88815
Kathy Cote
Member

Hi,
I try to run the following script. The script will create the new InDesign document from a .txt file. It names new files according to their sizes, save and close. It works.

Before closing, I would like to create a new text frame for each of the created files with the information of the third column [2] (or variable “c”). There is indeed a new text frame but I failed to insert my text “c”. I’m sure the problem is my variable but I can’t fix it.

I have a .txt file with 3 columns et 50 lines.

someone of you have the solution?

Your help is greatly appreciated,

Kathy

This is my code:
var file = File.openDialog(“Select Your Text File”, undefined, false);
var folder = Folder.selectDialog(“Select the folder where the new documents should be saved”);
file.open(“r”);
var content = file.read().split(“”);
var pageIndex;

for (var i = 0; i < content.length ; i++) {
var curLine = content[i].split(“”);
var w = curLine[0];
var h = curLine[1];
var c = curLine[2];

docName = w + “X” + h + “_” + c ;

try {
var newDoc = app.documents.add(false);
newDoc.documentPreferences.pageHeight = h;
newDoc.documentPreferences.pageWidth = w;

newDoc.save(new File(folder + “/” + docName + “.indd”));

if (pageIndex==undefined)pageIndex=0;
var newTextFrame=newDoc.pages[pageIndex].textFrames.add();
newTextFrame.newDoc=c; //it does not work

newDoc.close(SaveOptions.no)
} catch(myError){}
}

This article was last modified on October 3, 2016

Comments (0)

Loading comments...