Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

improve or simplify this batch script

$
0
0

sorry my bad english

Hello, I've combined some scripts in this forum, to make an image processor as Photoshop, I wonder if this script is right or if you can simplify more

 

This script convert AI to PSD, Pdf, Png, Jpg, AI v3 - cc2015, select resolution and included to subfolders (optional)

 

Español

 

hola, he combinado algunos scripts en este foro, para crear algo similar al procesador de photoshop, me gustaría saber si este script se puede mejorar o simplificar para que procese más rápido.

 

este script procesa un Ai a Psd, Pdf, Png, Jpg y Ai v3 hasta la CC2015, además puede escoger la resolución de la exportación para PSD,PNG y JPG, también uno puede elegir que busque en subcarpetas

 

 

 

var format = prompt('Choose a File Type Extension  :\nai, psd, pdf, jpg, png', "png", 'Batch');
if (format == "ai" || format == "psd" || format == "pdf" || format == "jpg" || format == "png") {  if (format == "jpg" || format == "png" || format == "psd") {  var res = prompt('DPI resolution ', 300, 'Batch');  }  if (format == "ai") {  alert("Adobe Ai versions :\n\nAdobe 3.0 = 3\n\nAdobe 8.0 = 8\n\nAdobe 9.0 = 9\n\nAdobe 10 = 10\n\nAdobe CS1 = 11\n\nAdobe CS2 = 12\n\nAdobe CS3 = 13\n\nAdobe CS4 = 14\n\nAdobe CS5 = 15\n\nAdobe CS6 = 16\n\nAdobe CC 2013,2014,2015 = 17")  var cs = prompt('Type Ai version ', 17, 'Batch');  }  var folder = Folder.selectDialog("Select Source Folder...");  var files;  var resolution = res;  var ver = cs;  //exporting  //var lFolder = new Folder(folder + "/" + format);  //lFolder.create();  if (folder != null) {  var subcarpets = prompt('Include subfolders when searching? yes o no?', "no", 'Batch');  if (subcarpets == "no" || subcarpets == "yes") {  if (subcarpets == "no") {  files = folder.getFiles("*.ai");  }  if (subcarpets == "yes") {  files = find_files(folder, ['.ai']);  }  var fileCount = files.length; // count them  var log = fileCount + ' Files Processed  to ' + format + '\n';  if (fileCount > 0) {  for (i = 0; i < fileCount; i++) {  var idoc = app.open(files[i]);  var tipe = files[i].name.substr(0, files[i].name.lastIndexOf('.')) || files[i].name;  if (format == "ai") {  exportAI();  }  if (format == "psd") {  exportPSD();  }  if (format == "pdf") {  exportPDF();  }  if (format == "jpg") {  exportJPG();  }  if (format == "png") {  exportPNG();  }  log += files[i] + " to " + tipe + "." + format + '\n';  }  alert(fileCount + ' file(s) processed to ' + format);  txtlog = new File(folder + '/textlog.txt');  var isopen = txtlog.open("w"); //open file for editing  if (isopen) //test file is open  {  txtlog.seek(0, 0);  txtlog.write(log);  txtlog.close();  }  } else {  alert("There are no Illustrator files in this folder.");  }  } else {  alert("sorry, the option \"" + subcarpets + "\" no exist.");  }  }
}


/////////////////////////////////////subfolders - Peter Kharel/////////////////////////////////////////////////////////////////
// recurse subfolders - Peter Kharel
function find_files(dir, mask_array) {
  var arr = [];  for (var i = 0; i < mask_array.length; i++) {  arr = arr.concat(find_files_sub(dir, [], mask_array[i].toUpperCase()));  }  return arr;
}


function find_files_sub(dir, array, mask) {
  var f = Folder(dir).getFiles('*.*');  for (var i = 0; i < f.length; i++) {  if (f[i]instanceof Folder) {  find_files_sub(f[i], array, mask);  } else if (f[i].name.substr(-mask.length).toUpperCase() == mask) {  array.push(f[i]);  }  }  return array;
}
//////////////////////////////////////TIPOS DE ARCHIVOS/////////////////////////////////////////////////////////////////


function exportPNG() {


  var pngExportOpts = new ExportOptionsPNG24();  pngExportOpts.antiAliasing = true;  pngExportOpts.artBoardClipping = true;  pngExportOpts.horizontalScale = (resolution / 72) * 100;  //pngExportOpts.matte = true;  //pngExportOpts.matteColor = 0, 0, 0;  pngExportOpts.saveAsHTML = false;  pngExportOpts.transparency = true;  pngExportOpts.verticalScale = (resolution / 72) * 100;  idoc.exportFile(files[i], ExportType.PNG24, pngExportOpts);  idoc.close(SaveOptions.DONOTSAVECHANGES);  return pngExportOpts;
}


function exportJPG() {


  var jpgExportOpts = new ExportOptionsJPEG();  jpgExportOpts.antiAliasing = true;  jpgExportOpts.qualitySetting = 100;  jpgExportOpts.horizontalScale = (resolution / 72) * 100;  jpgExportOpts.verticalScale = (resolution / 72) * 100;  jpgExportOpts.optimization = true;  jpgExportOpts.artBoardClipping = true;  idoc.exportFile(files[i], ExportType.JPEG, jpgExportOpts);  idoc.close(SaveOptions.DONOTSAVECHANGES);  return jpgExportOpts;
}


function exportAI() {


  var dest = new File(files[i] + "_v"+ver+".ai");  var illustratorSaveOpts = new IllustratorSaveOptions();  if (ver == 17) {  illustratorSaveOpts.compatibility = Compatibility.ILLUSTRATOR17;  }  if (ver == 16) {  illustratorSaveOpts.compatibility = Compatibility.ILLUSTRATOR16;  }  if (ver == 15) {  illustratorSaveOpts.compatibility = Compatibility.ILLUSTRATOR15;  }  if (ver == 14) {  illustratorSaveOpts.compatibility = Compatibility.ILLUSTRATOR14;  }  if (ver == 13) {  illustratorSaveOpts.compatibility = Compatibility.ILLUSTRATOR13;  }  if (ver == 12) {  illustratorSaveOpts.compatibility = Compatibility.ILLUSTRATOR12;  }  if (ver == 11) {  illustratorSaveOpts.compatibility = Compatibility.ILLUSTRATOR11;  }  if (ver == 10) {  illustratorSaveOpts.compatibility = Compatibility.ILLUSTRATOR10;  }  if (ver == 9) {  illustratorSaveOpts.compatibility = Compatibility.ILLUSTRATOR9;  }  if (ver == 8) {  illustratorSaveOpts.compatibility = Compatibility.ILLUSTRATOR8;  }  if (ver == 3) {  illustratorSaveOpts.compatibility = Compatibility.ILLUSTRATOR3;  }  illustratorSaveOpts.embedLinkedFiles = true;  illustratorSaveOpts.fontSubsetThreshold = 0.0  illustratorSaveOpts.pdfCompatible = true  illustratorSaveOpts.embedICCProfile = false  idoc.saveAs(dest, illustratorSaveOpts);  idoc.close(SaveOptions.DONOTSAVECHANGES);  return illustratorSaveOpts;


}


function exportPDF() {


  var pdfSaveOpts = new PDFSaveOptions();  pdfSaveOpts.acrobatLayers = false;  pdfSaveOpts.colorBars = false;  pdfSaveOpts.colorCompression = CompressionQuality.AUTOMATICJPEGHIGH;  pdfSaveOpts.compressArt = true; //default  pdfSaveOpts.embedICCProfile = true;  pdfSaveOpts.enablePlainText = true;  pdfSaveOpts.generateThumbnails = true; // default  pdfSaveOpts.optimization = true;  pdfSaveOpts.pageInformation = false;  pdfSaveOpts.preserveEditability = false;  idoc.saveAs(files[i], pdfSaveOpts);  idoc.close(SaveOptions.DONOTSAVECHANGES);  return pdfSaveOpts;


}


function exportPSD() {


  var psdExportOpts = new ExportOptionsPhotoshop();  idoc.documentColorSpace == DocumentColorSpace.CMYK ? psdExportOpts.imageColorSpace = ImageColorSpace.CMYK : psdExportOpts.imageColorSpace = ImageColorSpace.RGB;  psdExportOpts.antiAliasing = true;  psdExportOpts.embedICCProfile = true;  psdExportOpts.writeLayers = true;  psdExportOpts.resolution = resolution;  psdExportOpts.maximumEditability = true;  idoc.exportFile(files[i], ExportType.PHOTOSHOP, psdExportOpts);  idoc.close(SaveOptions.DONOTSAVECHANGES);  return psdExportOpts


}





Viewing all articles
Browse latest Browse all 12845

Trending Articles