Quantcast
Channel: Adobe Community : Popular Discussions - InDesign Scripting
Viewing all articles
Browse latest Browse all 15932

Undefined Variables

$
0
0

I have the following piece of script, used to import xml files from a folder to a template, but I can't get it to work.

var myTemplate = File("/E/template.indd");
var MyFolderWithFiles = Folder.selectDialog ("Choose a folder");
var myXMLDocs = MyFolderWithFiles.getFiles(".xml");

for(var i = 0; i < myXMLDocs.length; i++) {    //open template    var newDoc = app.open(myTemplate),    myDoc = app.activeDocument;    //import xml    newDoc.importXML(myXMLDocs[i]);     saveFiles();
}

function saveFiles() {
    var newFileName = MyFolderWithFiles.absoluteURI + "/Outputs/" + myXMLDocs[i].name.replace(/xml/,"indd");    newDoc.save(new File(newFileName));

 

}

I keep getting the message (in js console) "Error: myTemplate is undefined". Why is this happening? If I alert myTemplate, I get "/E/template.indd".


Viewing all articles
Browse latest Browse all 15932

Trending Articles