Skip to main content
Participant
March 9, 2015
Question

Extendscript - Batch processing Illustrator files - Performance Issue

  • March 9, 2015
  • 2 replies
  • 840 views

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.

This topic has been closed for replies.

2 replies

CarlosCanto
Community Expert
Community Expert
March 10, 2015

between opening and closing the file there is nothing to optimize, what are the times you were expecting?

this are my results, win8 i7

Processing in 06" 508 ms

Processing in 06" 156 ms

Processing in 05" 823 ms

Processing in 05" 615 ms

Participant
March 10, 2015

I have 2 expectations :

- opening and closing duration of several files exactly the same by script or manually.

- be able to process more than 10 files. Actually, i 've go a time out issue which requires Illustrator to be killed.

Thank you for your benchmark.

I'm pretty sure now that it is an issue due to the operating system.

I've tested it on different mac and results were between 2" and 1'34" !

>> I've found a dirty workaround by forcing to wait 150ms milliseconds ( line 06 ) in each loop so that illustrator can allocate the memory. (I think it's a memory issue, a garbage collector issue).

>> Not closing document speed up hugely the process.

I've processed 56 files in 21" 338 ms which is very acceptable, and it's possible to process a lot of files !

Thank you.

function run() {

     startTime = new Date();

     $.writeln('###############################################');

     if (files.length > 0 ) {

          for(i = 0; i < files.length  ; i++){  

         sleep(150);

          sourceDoc = app.open(files);

          processDoc(sourceDoc);

          }

     dlg.progBarFiles.value = 100;

     files = null;

     var duration = chrono(startTime);

        $.writeln('\nFINISH : ' + nbFileProcessed + ' Renderers processed in ' + duration );

        }

    return;

    }

function sleep(milliseconds) {

  var start = new Date().getTime();

  for (var i = 0; i < 1e7; i++) {

    if ((new Date().getTime() - start) > milliseconds){

      break;

    }

  }

}

Qwertyfly___
Legend
March 9, 2015

If your not doing anything with the file, there is no point in opening it and closing it just to get the filename.

just use --- $.writeln('Progression : ' + (i + 1) + '/' + files.length + ' : ' + files.name );

Participant
March 10, 2015

Hi,

I

f your not doing anything with the file, there is no point in opening it and closing it just to get the filename.

just use --- $.writeln('Progression : ' + (i + 1) + '/' + files.length + ' : + files.name );


You're right . In my whole script there is a huge process for each layer of each file.
Everything is working fine, except the batch performances.

Thank you.