Quantcast
Viewing all articles
Browse latest Browse all 12845

Speed and Stability in batch processing of files.

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[h]); // returns the document object  var idoc = sourceDoc;  var straypoints = [];  for (n=0; n<idoc.pathItems.length; n++) {  var ipath = idoc.pathItems[n];  if (ipath.pathPoints.length==1)  straypoints.push(ipath);  }  for (m=0; m<idoc.textFrames.length; m++) {  var itext = idoc.textFrames[m];  if (itext.textRange.length==0)  straypoints.push(itext);  }  for (k=0; k<straypoints.length; k++){  straypoints[k].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[t];  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[c];  ltr.characterAttributes.fillColor = sw.color;  }  }  }  for (var i=pi.length -1; i>=0; i--) {  var ipath = pi[i];  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[i].name==='Guide-die'){  return true;  }  }  return false;  }
}
$.gc();

Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>