Skip to main content
Inspiring
September 2, 2015
Question

Speed and Stability in batch processing of files.

  • September 2, 2015
  • 2 replies
  • 2607 views

My company is changing some aspects of our setup files. We have THOUSANDS. I have written a working script to work through all of them.

SPEED:

When I start the script I'll get as many as 10 per minute, but as the batch goes on it gets slower and slower. I let it run over night and it was down to one file every three minutes.

Right now my bandaid for this is to run 50 files at a time.

STABILITY:

When the script is finished I have to force quit illustrator because it is locked up.

I'm running IllustratorCC2015 on a mac OS X 10.10.5

I've wrapped the whole script in a function, and added $.gc(); garbage collection commands because of some tips I found here on the forum. Any advice on either issue would be most welcome. Here is my code.

// Main Code [Execution of script begins here]

regRemv();

function regRemv(){

  // uncomment to suppress Illustrator warning dialogs

  // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

  // establish save options

  var saveOptions = new IllustratorSaveOptions();

  saveOptions.compatibility = Compatibility.ILLUSTRATOR15;

  var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile;

  // Select the source folder.

  sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to process');

  // If a valid folder is selected

  if ( sourceFolder != null ){

  files = new Array();

  fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai, *.eps', '*' );

  // Get all files matching the pattern

  files = sourceFolder.getFiles( fileType );

  if ( files.length > 0 ){

  // Get the destination to save the files

  //destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted PDF files.', '~' );

  destFolder = sourceFolder;

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

  sourceDoc = app.open(files); // returns the document object

  var idoc = sourceDoc;

  var straypoints = [];

  for (n=0; n<idoc.pathItems.length; n++) {

  var ipath = idoc.pathItems;

  if (ipath.pathPoints.length==1)

  straypoints.push(ipath);

  }

  for (m=0; m<idoc.textFrames.length; m++) {

  var itext = idoc.textFrames;

  if (itext.textRange.length==0)

  straypoints.push(itext);

  }

  for (k=0; k<straypoints.length; k++){

  straypoints.remove();

  }

  var pi = idoc.pathItems;

  var tf = idoc.textFrames;

  createGuideDie()

  var sw = idoc.swatches['Guide-die'];

  // text frames with registration color change to die color.

  for (var t=tf.length -1; t>=0; t--) {

  var iTxtFrm = tf;

  var firstLtr = iTxtFrm.characters[0];

  var chars = iTxtFrm.characters;

  if (iTxtFrm.layer.visible === true && iTxtFrm.layer.locked === false && iTxtFrm.hidden === false && iTxtFrm.locked === false && firstLtr.characterAttributes.fillColor.typename === "SpotColor" && firstLtr.characterAttributes.fillColor.spot.name === "[Registration]"){

  for (var c=0; c<chars.length; c++) {

  var ltr = chars;

  ltr.characterAttributes.fillColor = sw.color;

  }

  }

  }

  for (var i=pi.length -1; i>=0; i--) {

  var ipath = pi;

  if (ipath.layer.visible === true && ipath.layer.locked === false && ipath.hidden === false && ipath.locked === false && ipath.stroked === true && ipath.strokeColor.typename === "SpotColor" && ipath.strokeColor.spot.name === "[Registration]"){

  // ipath.strokeColor = sw.color;

  ipath.remove();

  // ipath.stroked = false;

  } else if (ipath.layer.visible === true && ipath.layer.locked === false && ipath.hidden === false && ipath.locked === false && ipath.stroked === false && ipath.filled === false && Math.round(ipath.height) === 18 && Math.round(ipath.width) === 18){

  ipath.remove()

  }

  }

  var here = sourceDoc.fullName;

  sourceDoc.saveAs( here, saveOptions );

  sourceDoc.close();

  $.gc();

  $.gc();

  }

  }

  } else {

  alert( 'No matching files found' );

  }

  $.gc();

  // app.executeMenuCommand('closeAll');

  app.beep();

  alert(h + " finished processing");

  function createGuideDie(){

  if (!doesColorExist('Guide-die')){

  // Create CMYKColor

  var cmykColor = new CMYKColor();

  cmykColor.cyan = 28;

  cmykColor.magenta = 56;

  cmykColor.yellow = 0;

  cmykColor.black = 37;

  // Create Spot

  var spot = idoc.spots.add();

  spot.color = cmykColor;

  spot.colorType = ColorModel.SPOT;

  spot.name = 'Guide-die';

  }

  }

  function doesColorExist(){

  var clrs = idoc.swatches;

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

  if (clrs.name==='Guide-die'){

  return true;

  }

  }

  return false;

  }

}

$.gc();

This topic has been closed for replies.

2 replies

Inspiring
September 2, 2015
elDudereno: We have THOUSANDS. I have written a working script to work through all of them.


It seems to be related to memory leak/space issues, I have seen the same thing (slow, crawl, crash) mentioned regarding photoshop, after effects, indesign, etc., batch scripts as well, dating back well before CC...

As you well know from you own previous thread: batch script memory use CS5.1 vs CS6


----------------------------------------------------------------------------------------------------------------------------------------------

From the Illustrator Scripting Guide:

Known issues:

Scripts that create, save, and close many Illustrator files should periodically quit and relaunch Illustrator. The recommended maximum number of files to process before quitting and relaunching Illustrator is:

• Windows 500 files

• Mac OS 1000 files

The “An Illustrator error occurred: 1346458189 (“PARM”)” alert may be popped when badly written scripts are repeatedly run in Illustrator from the ESTK.

Scripters need to be very careful about variable initialization and namespace conflict when pushing a batch of Illustrator scripts repeatedly for execution in Illustrator via the ESTK in one Illustrator session. Each script run is executed within the same persistent ExtendScript engine within Illustrator.

^ That was copied pasted from the CS5 version, amazing they cant seem to fix/improve something that has been known for so long. The same verbiage is in the CS3 Guide from 8+ years ago.

Example Topic: https://forums.adobe.com/message/3254831


Post 16 - CarlosCanto May 13, 2013

I think I read somewhere that running a script a bunch of times causes the ESTK to crawl, it has a limit. Restart both the ESTK and Illustrator and try again, or also try running the script direct from within Illustrator... I may be wrong though.

Post 17 - Muppet Mark May 14, 2013


The guide also suggests a max of 1000 files on mac and 500 on pc if you are performing a batch routine…

----------------------------------------------------------------------------------------------------------------------------------------------

elDudereno: added $.gc(); garbage collection commands

You might also research about using: null, undefined, delete for your variables and functions once they are utilized to further clear/clean things up manually. However you still probably wont get around the file count limits mentioned above.

Inspiring
September 2, 2015

I was able to get my Maximum number of files per minute up to 13 at the beginning by adding this between lines 73 & 74.


// clean up

sourceDoc = null;

idoc = null;

straypoints = null;

n = null;

m = null;

pi = null;

tf = null;

sw = null;

t = null;

iTxtFrm = null;

firstLtr = null;

chars = null;

c = null;

ltr = null;

ipath = null;

here = null;

I'm sure some of this is redundant due to scope and whatnot, but I don't have a full grasp on that yet so I thought I'd be thorough.


But in next minute it's less and by the time I've run the 50 files the last full minute is only 4 files.


Illustrator is still locked up and I have to force quit.

Silly-V
Legend
September 2, 2015

Wow hey, what if you try to set ipath to null, every time you have an ipath.remove() ?
Will that make it even faster?

Silly-V
Legend
September 2, 2015

I sometimes have the same problem, and would also like to know what causes it and how to deal with it, in CC2015.