I've written a simple script to open two documents in Adobe Illustrator (File -> Scripts) and apply some commands to those documents.
The purpose of the script; with no documents open in Illustrator, the script will:
The script:
try
{
var doc_1 = open(File("C:/file1.ai"));
var doc_2 = open(File("C:/file2.ai"));
var sourceDoc;
var targetFile;
var options = new IllustratorSaveOptions();
for (var i = 0; i < app.documents.length; i++ )
{
sourceDoc = app.documents[i];
sourceDoc.importVariables(new File("C:/variables.xml"));
sourceDoc.dataSets[0].display();
targetFile = new File("C:/output" + sourceDoc.name + '.ai');
sourceDoc.saveAs( targetFile, options );
sourceDoc.close();
}
}
catch(err)
{
alert(err);
}
This code works only for the last opened file (file2.ai). file1.ai is never touched, almost as if there is no loop.
What could be causing this?
When closing the first file in the loop you just moved app.documents[1]
to app.documents[0]
You want top loop through them backwards
try your loop with
for (var i = app.documents.length; i >0 ; i-- )