Extendscript - Batch processing Illustrator files - Performance Issue
Hi,
! ! ! !
I'm facing an performance issue when executing the script below :
Is there a way to optimize the batch processing because it's critic on my project (i have to process hundreds files).
#target illustrator
var sourceDir,
startTime,
files,
sourceDoc,
duration = 0;
sourceDir = Folder.selectDialog( 'Select the import directory.', '~' );
files = sourceDir.getFiles("*.ai");
if(files.length == 0){
alert("No files to import");
}else{
$.writeln('###############################################');
startTime = new Date();
for(i=0; i < files.length; i++){
app.open(files);
$.writeln('Progression : ' + (i + 1) + '/' + files.length + ' : ' + app.activeDocument.name );
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
duration = chrono(startTime);
$.writeln('--------------------------------------------------------------------------');
$.writeln('Processing in ' + duration );
}
function chrono(start){
var diff = new Date - start;
diff = new Date(diff);
var diffString;
var msec = diff.getMilliseconds();
var sec = diff.getSeconds();
var min = diff.getMinutes();
var hr = diff.getHours()-1;
if (min < 10){
min = "0" + min;
}
if (sec < 10){
sec = "0" + sec;
}
if(msec < 10){
msec = "00" +msec;
}
else if(msec < 100){
msec = "0" +msec;
}
if (min == 0){
diffString = String( sec + '" ' + msec + ' ms');
}
else {
diffString = String( min + "' " + sec + '" ' + msec + ' ms');
}
// startTime = diff;
return diffString;
}
- I select a folder with 7 Illustrator Files which are empty (to minimize the process)

The script process all files.
At the end the Illustrator is overloaded during several seconds.
###############################################
Progression : 1/7 : test1 2.ai
Progression : 2/7 : test1 3.ai
Progression : 3/7 : test1 4.ai
Progression : 4/7 : test1 5.ai
Progression : 5/7 : test1 6.ai
Progression : 6/7 : test1 7.ai
Progression : 7/7 : test1 8.ai
--------------------------------------------------------------------------
Processing in 23" 018 ms
The script crashes when i select a folder which contains too many files.
Exectution time varies from 2" to 24". (I don't know why)
Can you test it on you machine - I suppose, that it is a system issue
System Software Overview:
System Version: OS X 10.10.2 (14C109)
Kernel Version: Darwin 14.1.0
Boot Volume: Macintosh HD
Boot Mode: Normal
Adobe Illustrator 18.1.11
Thank You.
