Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Batch Script for EPS-Files

Community Beginner ,
Oct 21, 2016 Oct 21, 2016

Hello, I am new to this forum and would like to say hello to everybody. Thank you in advance for any help.

Now to my question.

I have a problem with some EPS-Files. We have around 6'000 EPS-Files. They have all the same size and "corner marks" at the corners.

Now I am looking for a Batch Script (for Mac, AI CS5 or CC), that opens opens one EPS-File out of a given folder, cuts off the corner marks, adds the space back again - so that the old size is back and saves the file in a given folder as EPS-File, changing the File-Name at the end with "-op.eps".

The Script should run for all the EPS-Files in the given folder (in), and should save them in an given folder (out).

Is there someone who can program a Script that can do this or help me to program this Script by myself?

We need the Script, because we will get later more of the files and need them to convert them with a Batch-Script again.

We are willing to pay for the Script.

Thank you in advance for your help.

Best regards

Gordian

Example:

Example-corner-mark.png

TOPICS
Scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Oct 27, 2016 Oct 27, 2016

Gordian, hello!

If I understand correctly, you need to add option:

epsSaveOpts.artboardRange = '1';

But the current version of the script must do it New  (sets the size of the artboards along the crop marks (if any, or leave artboard as is)). Or until now not?

Translate
Adobe
Engaged ,
Oct 21, 2016 Oct 21, 2016

cleaningcrew, hello!

For a complete understanding, give a one base EPS-file and resulting EPS-file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 21, 2016 Oct 21, 2016

prototype of the script - dialog interface

(function batchEps () {

  var inputPath    = '',

      outPath      = '',

      inputFolder  = new Folder (inputPath),

      outputFolder = new Folder (outPath);

  var w         = new Window ('dialog', 'Batch EPS'),

      folderPan = w.add ('panel', undefined, 'Folders'),

      inGr      = folderPan.add ('group'),

      outGr     = folderPan.add ('group'),

      inFld     = inGr.add ('edittext', [0, 0, 300, 25]),

      inBtn     = inGr.add ('button', [0, 0, 100, 25], 'Input from'),

      outFld    = outGr.add ('edittext', [0, 0, 300, 25]),

      outBtn    = outGr.add ('button', [0, 0, 100, 25], 'Output to'),

      btnGr     = w.add ('group'),

      btnBatch  = btnGr.add ('button', undefined, 'Batch'),

      btnCansel = btnGr.add ('button', undefined, 'Cancel');

  w.alignChildren = 'right';

  inBtn.onClick  = function () {

    inputFolder = Folder.selectDialog ();

    inFld.text  = inputFolder;

  }

  outBtn.onClick = function () {

    outputFolder = Folder.selectDialog ();

    outFld.text  = outputFolder;

  }

  btnBatch.onClick = function () {

    alert (inputFolder + '\nInput folder exists status: ' + inputFolder.exists + '\n' +

      outputFolder + '\nOutput folder exists status: ' + outputFolder.exists);

  }

  w.show ();

} ());

If I'm going the right way and when you give me the sample EPS files (that I asked above) then I try to write whole script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 21, 2016 Oct 21, 2016

Hello o-marat

Thank you for the fast answer. Attached I send a link to one original file and one new file.

http://www.ghc-gmbh.ch/download/iec60417-5126.eps

http://www.ghc-gmbh.ch/download/iec60417-5126-new.eps

The point is, that in the original file are "corner marks". And this "coner marks" should be deleted, because the new file should be used in an other program, where the corner marks are disturbing. But the proportion and size of the main content should not be altert.

Thank you and best regards

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 21, 2016 Oct 21, 2016

Is this layout structure always as in sample EPS:

  • all in group;
  • then clipping group;
  • 4 crop marks at the very bottom of the clipping group?

How we can clearly identify the crop marks? What are some differences from the objects of the main content?

New This is important, since the crop marks - a conventional Bezier curves. In fact, they are no different from other design elements.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 21, 2016 Oct 21, 2016

No, in newer files the crop marks are in a own layer with a name.

In the half of the EPS the crop marks are like in the sample EPS.

The crop marks are always at the corners of an imagined square around the drawn object.

I thought, if I could make the working space a little smaller - 2 pixel - as the square of the crop marks, they will be deleted.

And if I than make the square again 2 pixel bigger, I will have the right size of the working space back again.

Saving this as a new EPS should bring an EPS without the crop marks but same working space size.

I know it is a little bit complex. The EPS where produced continuous over 20 years.

Thank you for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 22, 2016 Oct 22, 2016

It work only in CS6+, not CS5 (it will be more difficult).

Try to run on a small number of different files (10-20).

If some files are processed with errors, give me the problematic files for analysis.

/**

* ai.jsx (c)MaratShagiev m_js@bk.ru 21.10.2016

*/

//@target illustrator

(function batchEps() {

  var inputPath    = '',

      outPath      = '',

      inputFolder  = new Folder(inputPath),

      outputFolder = new Folder(outPath);

  var w         = new Window('dialog', 'Batch EPS'),

      folderPan = w.add('panel', undefined, 'Folders'),

      inGr      = folderPan.add('group'),

      outGr     = folderPan.add('group'),

      inFld     = inGr.add('edittext', [0, 0, 300, 25]),

      inBtn     = inGr.add('button', [0, 0, 100, 25], 'Input from'),

      outFld    = outGr.add('edittext', [0, 0, 300, 25]),

      outBtn    = outGr.add('button', [0, 0, 100, 25], 'Output to'),

      btnGr     = w.add('group'),

      btnBatch  = btnGr.add('button', undefined, 'Batch'),

      btnCansel = btnGr.add('button', undefined, 'Cancel');

  w.alignChildren = 'right';

  inBtn.onClick  = function() {

    inputFolder = Folder.selectDialog();

    inFld.text  = inputFolder;

  }

  outBtn.onClick = function() {

    outputFolder = Folder.selectDialog();

    outFld.text  = outputFolder;

  }

  btnBatch.onClick = function() {

    if (!inputFolder.exists) {

      alert('Incorrect input folder');

      return;

    }

    if (!outputFolder.exists) {

      alert('Incorrect output folder');

      return;

    }

    var inputFiles  = inputFolder.getFiles("*.eps");

    var epsSaveOpts = new EPSSaveOptions();

    epsSaveOpts.cmykPostScript             = false;

    epsSaveOpts.compatibility              = Compatibility.ILLUSTRATOR10;

    epsSaveOpts.compatibleGradientPrinting = false;

    epsSaveOpts.embedAllFonts              = false;

    epsSaveOpts.embedAllFonts              = false;

    epsSaveOpts.flattenOuput               = OutputFlattening.PRESERVEAPPEARANCE;

    epsSaveOpts.includeDocumentThumbnails  = false;

    epsSaveOpts.overprint                  = PDFOverprint.PRESERVEPDFOVERPRINT;

    epsSaveOpts.postScript                 = EPSPostScriptLevelEnum.LEVEL2;

    epsSaveOpts.preview                    = EPSPreview.None;

    epsSaveOpts.saveMultipleArtboards      = false;

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

      var epsFile = inputFiles;

      open(epsFile);

      var epsSaveFile = new File(outputFolder + '/' + activeDocument.name + '-op.eps');

      delCrops();

      activeDocument.saveAs(epsSaveFile, epsSaveOpts);

      activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    }

    w.close();

  }

  w.show();

  /**

   * LIBRARY

   * */

  function delCrops() {

    executeMenuCommand('selectall');

    var bnds   = _getSelBnds(selection),

        doc    = activeDocument,

        indent = 4,

        rmCnt  = 0,

        left, top, right, bott,

        i, j;

    left  = bnds[0][0] + indent;

    top   = bnds[0][1] - indent;

    right = bnds[0][2] - indent;

    bott  = bnds[0][3] + indent;

    nextPth: for (i = doc.pathItems.length - 1; i >= 0; i--) {

      var pth = doc.pathItems;

      if (pth.selected == false) continue;

      if (pth.closed) continue;

      if (pth.pathPoints.length > 4) continue;

      for (j = 0; j < pth.pathPoints.length; j++) {

        var pnt = pth.pathPoints;

        var x   = pnt.anchor[0];

        var y   = pnt.anchor[1];

        if (x <= left || x >= right || y >= top || y <= bott) {

          continue;

        } else {

          continue nextPth;

        }

      }

      pth.remove();

      rmCnt++;

    }

    _delEmptyLays();

    _delHideLays();

    return rmCnt;

    /**

     * get selection.bounds:  [left, top, right, bottom]

     * calculate wdth, hght по bounds

     *

     * @param [Object/Collection]

     * @return {Array} [ bounds, wdth, hght ]

     */

    function _getSelBnds(sel) {

      if (!arguments.length) {

        throw new Error('The function GetSelBndsExtend_v2 does not gotten an arguments');

      }

      if (arguments.length > 1) {

        throw new Error('The function GetSelBndsExtend_v2 expected one argument');

      }

      if (arguments[0] === null) {

        throw new Error('The function GetSelBndsExtend_v2 has gotten a "null"');

      }

      if (typeof arguments[0] != 'object') {

        throw new Error('The function GetSelBndsExtend_v2 has unexpected argument');

      }

      var bnds, wdth, hght,

          elL, elT, elR, elB;

      try {

        bnds = _getBounds(sel, []);

      } catch (e) {

        '_getBounds error\n' + 'line: ' + e.line + '\nmessage: ' + e.message;

      }

      try {

        wdth = _calcElemW(bnds);

      } catch (e) {

        '_calcElemW error\n' + 'line: ' + e.line + '\nmessage: ' + e.message;

      }

      try {

        hght = _calcElemH(bnds);

      } catch (e) {

        '_calcElemH error\n' + 'line: ' + e.line + '\nmessage: ' + e.message;

      }

      return [bnds, wdth, hght];

      /**

       * LIB

       * */

      function _getBounds(pile, bnds) {

        if (pile.typename == 'PathItem' || pile.typename == 'CompoundPathItem') {

          return pile.geometricBounds;

        }

        for (var j = 0; j < pile.length; j++) {

          var el = pile ;

          if (el.typename != 'GroupItem') { // anything axcept a group

            if (bnds == '') {

              bnds = el.geometricBounds;

              continue;

            }

            bnds = _compareBounds(el, bnds);

          }

          if (el.typename == 'GroupItem' && el.clipped) { // clipped group => search a mask

            var groupPaths = el.pathItems;

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

              if (groupPaths.clipping) {

                if (bnds == '') {

                  bnds = groupPaths.geometricBounds;

                  continue;

                }

                bnds = _compareBounds(groupPaths, bnds);

              }

            }

          }

          if (el.typename == 'GroupItem' && !el.clipped && !el.groupItems) { // group havn't groups and mask

            if (bnds == '') {

              bnds = el.geometricBounds;

              continue;

            }

            bnds = _compareBounds(el.geometricBounds, bnds);

          }

          if (el.typename == 'GroupItem' && !el.clipped && el.groupItems) { // masks NO, groups YES => recurs

            bnds = _getBounds(el.pageItems, bnds);

            continue;

          }

        }

        return bnds;

      }

      function _compareBounds(elem, bndsToCompare) {

        var elemBounds = elem.geometricBounds;

        return [Math.min(elemBounds[0], bndsToCompare[0]),

          Math.max(elemBounds[1], bndsToCompare[1]),

          Math.max(elemBounds[2], bndsToCompare[2]),

          Math.min(elemBounds[3], bndsToCompare[3])];

      }

      function _calcElemW(bnds) {

        var elemWidth = 0,

            left      = bnds[0],

            right     = bnds[2];

        (left <= 0 && right <= 0) || (left >= 0 && right >= 0) ? elemWidth = Math.abs(left - right) : '';

        left <= 0 && right >= 0 ? elemWidth = Math.abs(left) + right : '';

        return elemWidth;

      }

      function _calcElemH(bnds) {

        var elemHeight = 0,

            top        = bnds[1],

            bottom     = bnds[3];

        (top <= 0 && bottom <= 0) || (top >= 0 && bottom >= 0) ? elemHeight = Math.abs(top - bottom) : '';

        top >= 0 && bottom <= 0 ? elemHeight = top + Math.abs(bottom) : '';

        return elemHeight;

      }

    }

    function _delHideLays() {

      var d = activeDocument,

          i;

      for (i = d.layers.length - 1; i >= 0; i--) {

        var lay = d.layers;

        if (lay.visible) continue;

        lay.visible = true;

        lay.locked  = false;

        lay.remove();

      }

    }

    /**

     * recirsively remove empty layers and sublayers

     */

    function _delEmptyLays() {

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

        var lay = activeDocument.layers;

        if (_hasSubs(lay)) {

          _delSubs(lay);

        }

        // NOTE: trying to remove the only existing layer will lead to its renaming to <layer>

        if (_isEmpty(lay) && activeDocument.layers.length > 1) {

          lay.locked == true ? lay.locked = false : '';

          lay.visible == false ? lay.visible = true : '';

          lay.remove();

          i--;

        }

      }

      /**

       * recursively remove sublayer

       * @param {Object} lay - object of Layer class

       * @return {Object} lay - object of Layer class

       */

      function _delSubs(lay) {

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

          var thisSubLay = _getSubs(lay);

          if (_isEmpty(thisSubLay)) {

            thisSubLay.locked == true ? thisSubLay.locked = false : '';

            thisSubLay.visible == false ? thisSubLay.visible = true : '';

            thisSubLay.remove();

            i--;

          }

          if (_hasSubs(thisSubLay)) {

            var parent = _delSubs(thisSubLay);

            if (_isEmpty(parent)) {

              thisSubLay.locked == true ? thisSubLay.locked = false : '';

              thisSubLay.visible == false ? thisSubLay.visible = true : '';

              thisSubLay.remove();

              i--;

            }

          }

        }

        return lay;

      }

      /**

       * @param  {Object} lay - object of Layer class

       * @return {Boolean} true, if has sublayers

       */

      function _hasSubs(lay) {

        try {

          return (lay.layers.length > 0);

        } catch (e) {

          return false;

        }

      }

      /**

       * if layer contained object of classes PageItem or Layer

       * @param  {Object} lay - object of Layer class

       * @return {Boolean} true, if layer is empty

       */

      function _isEmpty(lay) {

        try {

          return lay.pageItems.length == 0 && lay.layers.length == 0;

        } catch (e) {

          return false;

        }

      }

      /**

       * get sublayers collection from current layer

       * @param  {Object} lay - object of Layer class

       * @return {Object/Boolean} - collection of Layers or false

       */

      function _getSubs(lay) {

        try {

          return lay.layers;

        } catch (e) {

          return false;

        }

      }

    }

  }

}());

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 24, 2016 Oct 24, 2016

Hello o-marat

Thank you so far. That works nicely. The crop marks are gone. I have tested it with CC. Maybe I will run it with CC only. That makes things more easy.

But there are three points which I like to change.

1. While the files (eps) are opened, there comes a message about colours. This comes at each file, what is annoying. See attached screen shoot (1). I do not know how to switch off this message? Any idea?

Bildschirmfoto 2016-10-24 um 11.37.14.png

2. The Files are saved with the filename incl. the addition "-op.eps". The Name looks now like: "din33450-0001.eps-op.eps" - I like to get the file name: "din33450-0001-op.eps" screen shot (2).

Bildschirmfoto 2016-10-24 um 11.37.37.png

3. The new files have a workspace like the standard Document size. The wokrspace should be only the space which was defined by the crop marks before. Is this possible?

Bildschirmfoto 2016-10-24 um 11.39.11.png

Thank you in advance.

Gordian

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 24, 2016 Oct 24, 2016

Gordian, hi! All clearly. Points (2) and (3) will be fixed today, point (1) - I try to fix it today.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 24, 2016 Oct 24, 2016

Gordian, can you give me some more files (such as those in the screenshot) to test? Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 24, 2016 Oct 24, 2016

Please, try this version.

Terms of the successful execution of the script:

  • Illustrator CS6+
  • Crop marks (which on a separate layer) should be unlocked.
  • And should be no hidden layers (except layers with crop marks).

/**

* ai.jsx (c)MaratShagiev m_js@bk.ru 24.10.2016

* */

//@target illustrator

(function batchEps () {

  var inputPath    = '',

      outPath      = '',

      inputFolder  = new Folder (inputPath),

      outputFolder = new Folder (outPath);

  var w         = new Window ('dialog', 'Batch EPS'),

      folderPan = w.add ('panel', undefined, 'Folders'),

      inGr      = folderPan.add ('group'),

      outGr     = folderPan.add ('group'),

      inFld     = inGr.add ('edittext', [0, 0, 300, 25]),

      inBtn     = inGr.add ('button', [0, 0, 100, 25], 'Input from'),

      outFld    = outGr.add ('edittext', [0, 0, 300, 25]),

      outBtn    = outGr.add ('button', [0, 0, 100, 25], 'Output to'),

      btnGr     = w.add ('group'),

      btnBatch  = btnGr.add ('button', undefined, 'Batch'),

      btnCansel = btnGr.add ('button', undefined, 'Cancel');

  w.alignChildren = 'right';

  inBtn.onClick  = function () {

    inputFolder = Folder.selectDialog ();

    inFld.text  = inputFolder;

  }

  outBtn.onClick = function () {

    outputFolder = Folder.selectDialog ();

    outFld.text  = outputFolder;

  }

  btnBatch.onClick = function () {

    try {

      app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

      if (!inputFolder.exists) {

        alert ('Incorrect input folder');

        return;

      }

      if (!outputFolder.exists) {

        alert ('Incorrect output folder');

        return;

      }

      var inputFiles  = inputFolder.getFiles ("*.eps");

      var epsSaveOpts = new EPSSaveOptions ();

      epsSaveOpts.cmykPostScript             = false;

      epsSaveOpts.compatibility              = Compatibility.ILLUSTRATOR15;

      epsSaveOpts.compatibleGradientPrinting = false;

      epsSaveOpts.embedAllFonts              = false;

      epsSaveOpts.embedLinkedFiles           = false;

      epsSaveOpts.flattenOuput               = OutputFlattening.PRESERVEAPPEARANCE;

      epsSaveOpts.includeDocumentThumbnails  = false;

      epsSaveOpts.overprint                  = PDFOverprint.PRESERVEPDFOVERPRINT;

      epsSaveOpts.postScript                 = EPSPostScriptLevelEnum.LEVEL2;

      epsSaveOpts.preview                    = EPSPreview.None;

      epsSaveOpts.saveMultipleArtboards      = false;

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

        var epsFile = inputFiles;

        open (epsFile);

        var epsSaveFile = new File (outputFolder + '/' + activeDocument.name.slice (0, -4) + '-op.eps');

        delCrops ();

        activeDocument.saveAs (epsSaveFile, epsSaveOpts);

        activeDocument.close (SaveOptions.DONOTSAVECHANGES);

      }

      w.close ();

    } catch (e) {

    } finally {

      app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;

    }

  }

  w.show ();

  /**

   * LIBRARY

   * */

  function delCrops () {

   

    _showUnlockLays ();

    executeMenuCommand ('selectall');

    executeMenuCommand ('Fit Artboard to selected Art');

    var bnds   = activeDocument.artboards[0].artboardRect,

        doc    = activeDocument,

        indent = 4,

        rmCnt  = 0,

        left, top, right, bott,

        i, j;

    left  = bnds[0] + indent;

    top   = bnds[1] - indent;

    right = bnds[2] - indent;

    bott  = bnds[3] + indent;

    nextPth: for (i = doc.pathItems.length - 1; i >= 0; i--) {

      var pth = doc.pathItems;

      if (pth.selected == false) continue;

      if (pth.closed) continue;

      if (pth.pathPoints.length > 4) continue;

      for (j = 0; j < pth.pathPoints.length; j++) {

        var pnt = pth.pathPoints;

        var x   = pnt.anchor[0];

        var y   = pnt.anchor[1];

        if (x <= left || x >= right || y >= top || y <= bott) {

          continue;

        } else {

          continue nextPth;

        }

      }

      pth.remove ();

      rmCnt++;

    }

    return rmCnt;

    function _showUnlockLays () {

      var d = activeDocument,

          i;

      for (i = d.layers.length - 1; i >= 0; i--) {

        var lay = d.layers;

        if (lay.visible) continue;

        lay.visible = true;

        lay.locked  = false;

      }

    }

  }

} ());

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 24, 2016 Oct 24, 2016

Hello o-marat and thank you for your excellent work. But I still found some points, which should be repaired:

1. I could not stop the script with the cancel button while saving an eps file.

2. I could not stop the script with the general cancel button in the script.

3. The script did not stopped after the last processed file. I had to shot down Illustrator by finder.

4. One file was not processed https://www.ghc-gmbh.ch/download/iso7001-0019.eps maybe you can find out what happend here?

The other test files (i used 32 objects) worked fine.

Thank you

Gordian

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 24, 2016 Oct 24, 2016

As long as we debug the script, can you run the it from EcstendScript Toolkit?

In this case you can stop execution at any time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 24, 2016 Oct 24, 2016

Let's try again

/**

* ai.jsx (c)MaratShagiev m_js@bk.ru 25.10.2016

* */

//@target illustrator

(function batchEps() {

  var inputPath    = '',

      outPath      = '',

      inputFolder  = new Folder(inputPath),

      outputFolder = new Folder(outPath),

      convCount    = 0,

      start        = new Date();

  var w            = new Window('dialog', 'Batch EPS'),

      folderPan    = w.add('panel', undefined, 'Folders'),

      inGr         = folderPan.add('group'),

      outGr        = folderPan.add('group'),

      inFld        = inGr.add('edittext', [0, 0, 300, 25]),

      inBtn        = inGr.add('button', [0, 0, 100, 25], 'Input from'),

      outFld       = outGr.add('edittext', [0, 0, 300, 25]),

      outBtn       = outGr.add('button', [0, 0, 100, 25], 'Output to'),

      btnGr        = w.add('group'),

      btnBatch     = btnGr.add('button', undefined, 'Batch'),

      btnCansel    = btnGr.add('button', undefined, 'Cancel');

  w.alignChildren = 'right';

  inBtn.onClick    = function() {

    inputFolder = Folder.selectDialog();

    inFld.text  = inputFolder;

  }

  outBtn.onClick   = function() {

    outputFolder = Folder.selectDialog();

    outFld.text  = outputFolder;

  }

  btnBatch.onClick = function() {

    $.hiresTimer / 1000000;

    var userInteractLevelStore = app.userInteractionLevel;

    app.userInteractionLevel   = UserInteractionLevel.DONTDISPLAYALERTS;

    if (!inputFolder.exists) {

      alert('Incorrect input folder');

      return;

    }

    if (!outputFolder.exists) {

      alert('Incorrect output folder');

      return;

    }

    var inputFiles  = inputFolder.getFiles("*.eps");

    var epsSaveOpts = new EPSSaveOptions();

    epsSaveOpts.cmykPostScript             = false;

    epsSaveOpts.compatibility              = Compatibility.ILLUSTRATOR10;

    epsSaveOpts.compatibleGradientPrinting = false;

    epsSaveOpts.embedAllFonts              = false;

    epsSaveOpts.embedLinkedFiles           = false;

    epsSaveOpts.flattenOuput               = OutputFlattening.PRESERVEAPPEARANCE;

    epsSaveOpts.includeDocumentThumbnails  = false;

    epsSaveOpts.overprint                  = PDFOverprint.PRESERVEPDFOVERPRINT;

    epsSaveOpts.postScript                 = EPSPostScriptLevelEnum.LEVEL2;

    epsSaveOpts.preview                    = EPSPreview.None;

    epsSaveOpts.saveMultipleArtboards      = false;

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

      try {

        var epsFile = inputFiles;

        app.open(epsFile);

        var epsSaveFile = new File(outputFolder + '/' + activeDocument.name.slice(0, -4) + '-op.eps');

        delCrops();

        activeDocument.saveAs(epsSaveFile, epsSaveOpts);

        activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        convCount++;

      } catch (e) {

        continue;

      }

    }

    w.close();

    app.userInteractionLevel = userInteractLevelStore;

    /* $.writeln(new Date());

     $.writeln('execution time: ' + $.hiresTimer / 1000000);

     $.writeln('converted files: ' + convCount);*/

  }

  w.show();

  /**

   * LIBRARY

   * */

  function delCrops() {

    _showUnlockLays();

    executeMenuCommand('selectall');

    executeMenuCommand('Fit Artboard to selected Art');

    var bnds   = activeDocument.artboards[0].artboardRect,

        doc    = activeDocument,

        indent = 4,

        rmCnt  = 0,

        left, top, right, bott,

        i, j;

    left  = bnds[0] + indent;

    top   = bnds[1] - indent;

    right = bnds[2] - indent;

    bott  = bnds[3] + indent;

    nextPth: for (i = doc.pathItems.length - 1; i >= 0; i--) {

      var pth = doc.pathItems;

      if (pth.selected == false) continue;

      if (pth.closed) continue;

      if (pth.pathPoints.length > 4) continue;

      for (j = 0; j < pth.pathPoints.length; j++) {

        var pnt = pth.pathPoints;

        var x   = pnt.anchor[0];

        var y   = pnt.anchor[1];

        if (x <= left || x >= right || y >= top || y <= bott) {

          continue;

        } else {

          continue nextPth;

        }

      }

      pth.remove();

      rmCnt++;

    }

    return rmCnt;

    function _showUnlockLays() {

      var d = activeDocument,

          i;

      for (i = d.layers.length - 1; i >= 0; i--) {

        var lay     = d.layers;

        lay.visible = true;

        lay.locked  = false;

        executeMenuCommand('showAll');

        executeMenuCommand('unlockAll');

      }

    }

  }

}());

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 25, 2016 Oct 25, 2016

Thank you o-marat

I now tested it with a large amount of files - 160.

The files all where good. I tested it also with the one error file and this was good too.

It took 20 Minutes to convert this 160 Files. So 8'000 Files will take 17 hours (but see errors).

But there are still some errors.

1. The script will become slower as more files where processed. At the beginning of the test it could ca. process 5 files a minute, at the end of 160 files it only could process 3 files a minute. I assume that it will become much slower after 2'000 or 3'000 or even 4'000 files? This will extend the hole time a lot. What do you think?

2. Even in the EcstendScript Toolkit I could not stop the script neither in Illustrator.

Can you fix this problems? Thank you in advance.

Best regards

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 25, 2016 Oct 25, 2016

About point 2:

Do you run the code for this algorithm?

  • paste extendscript code to ExtendScript Editor window
  • run code by Run button (or Cmd R) in  ExtendScript Editor
  • stop execution (if it is needed) by Stop button (or Cmd K) in  ExtendScript Editor

(ExtendScript reference, page 29)

The Stop button should work... Although I have no way to verify in the absence of Mac.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 25, 2016 Oct 25, 2016

Ok, my mistake was, that the ExtendScript Editor was set to "CS 4". I set it now to "CC" and I can stop the Script over ExtendScript Editor.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 25, 2016 Oct 25, 2016

About point 1.

I find it difficult at the moment to say why the process is slowed down. File processing speed depends on the number of path items in the file, and on the speed of your computer. The reasons can be many. (Once it turned out that the user has a problem with the HDD. As soon as he changed the HDD, the script began to work normally).

I just spent tests (Win10x64Rus, CPU Corei7, RAM 8 Gb, CC2015x64En):

handled 512 files, and forcibly interrupted execution at five hundred file.

Speed is 15-35 files per minute, 501 files per 19 minutes. I did not see the slowing down at the end of execution.

Updated Allow me to test your most complex files.

And yet, at this stage I would advise to run a script with no more than 100-200 files simultaneously.

ps. Scripts do not run faster than the Illustrator. Acceleration only by eliminating the human factor.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 25, 2016 Oct 25, 2016

As I think, the slowest operation of the script:

  1. opening the file;
  2. iterating the path items in the file (search by condition, removal of the element when matching);
  3. save in .eps format.

It seems that I can affect the second point. However, steps 1 and 3 can often run much slower than 2.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 25, 2016 Oct 25, 2016

Hello o-marat

Thank you so far.

I think the problem with the speed was my anti-virus program. I am running on a MacBook with 2.7 GHz Intel Core i7, 16 GB RAM and Mac OS X 10.11.6. If I switch off anti-virus real-time checking it goes much faster. I think I can stand it to wait some hours.

But I have a different, more important problem. Some of the converted Files do not have a appropriate workspace any more. I give you some examples:

Bildschirmfoto 2016-10-25 um 18.08.09.png

Bildschirmfoto 2016-10-25 um 18.09.57.png

On the left the converted file and on the right side the original file.

In other cases it worked fine. See next example.

Bildschirmfoto 2016-10-25 um 18.11.50.png

Bildschirmfoto 2016-10-25 um 18.13.08.png

You can download this files and some others to work with here. The examples are enclosed:

https://www.ghc-gmbh.ch/download/Testfiles.zip

Do you think you can manage it, that this files have also the same Artspace / Workspace?

Thank you much in advance.

Best regards

Gordian

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 26, 2016 Oct 26, 2016

I try to reproduce the bug and I could not – all files in submitted testing archive are processed without errors  (so the archive is contains already processed files, but I mean the source files in it).

The artboard may stick to the edges of the image in one case – if there are no crop marks.

To avoid errors in the files, where for some reason there is no crop marks, I have added a checking for remove the 4 crop marks. If the crop marks have not been removed, it will return the previous artbords borders.

Now all should be fine:

/**

* Adobe Illustrator CS6+ ExtendScript (c)MaratShagiev m_js@bk.ru 26.10.2016

* */

//@target illustrator

(function batchEps () {

  var inputPath    = '',

      outPath      = '',

      inputFolder  = new Folder (inputPath),

      outputFolder = new Folder (outPath);

  var w         = new Window ('dialog', 'Batch EPS'),

      folderPan = w.add ('panel', undefined, 'Folders'),

      inGr      = folderPan.add ('group'),

      outGr     = folderPan.add ('group'),

      inFld     = inGr.add ('edittext', [0, 0, 300, 25]),

      inBtn     = inGr.add ('button', [0, 0, 100, 25], 'Input from'),

      outFld    = outGr.add ('edittext', [0, 0, 300, 25]),

      outBtn    = outGr.add ('button', [0, 0, 100, 25], 'Output to'),

      btnGr     = w.add ('group'),

      btnBatch  = btnGr.add ('button', undefined, 'Batch'),

      btnCansel = btnGr.add ('button', undefined, 'Cancel');

  w.alignChildren  = 'right';

  inBtn.onClick    = function () {

    inputFolder = Folder.selectDialog ();

    inFld.text  = inputFolder;

  }

  outBtn.onClick   = function () {

    outputFolder = Folder.selectDialog ();

    outFld.text  = outputFolder;

  }

  btnBatch.onClick = function () {

    var userInteractLevelStore = app.userInteractionLevel;

    app.userInteractionLevel   = UserInteractionLevel.DONTDISPLAYALERTS;

    if (!inputFolder.exists) {

      alert ('Incorrect input folder');

      return;

    }

    if (!outputFolder.exists) {

      alert ('Incorrect output folder');

      return;

    }

    var inputFiles  = inputFolder.getFiles ("*.eps");

    var epsSaveOpts = new EPSSaveOptions ();

    modEpsSaveOpts (epsSaveOpts);

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

      var rmCount;

      try { // try-catch needed when found DCS EPS file, that can't be opened

        var epsFile = inputFiles;

        app.open (epsFile);

        var abRect = activeDocument.artboards[0].artboardRect;

        showAndUnlock ();

        executeMenuCommand ('selectall');

        executeMenuCommand ('Fit Artboard to selected Art');

        var epsSaveFile = new File (outputFolder + '/' + activeDocument.name.slice (0, -4) + '-op.eps');

        rmCount         = delCrops ();

        if (rmCount < 4) {

          activeDocument.artboards[0].artboardRect = abRect;

        }

        activeDocument.saveAs (epsSaveFile, epsSaveOpts);

        activeDocument.close (SaveOptions.DONOTSAVECHANGES);

      } catch (e) {

      }

    }

    w.close ();

    app.userInteractionLevel = userInteractLevelStore;

  }

  w.show ();

  /**

   * LIBRARY

   * */

  function delCrops () {

    var rmCount = 0;

    try {

      var bnds   = activeDocument.artboards[0].artboardRect,

          doc    = activeDocument,

          indent = 4,

          left, top, right, bott,

          i, j;

      left  = bnds[0] + indent;

      top   = bnds[1] - indent;

      right = bnds[2] - indent;

      bott  = bnds[3] + indent;

      nextPth: for (i = doc.pathItems.length - 1; i >= 0; i--) {

        var pth = doc.pathItems;

        if (pth.selected == false) continue;

        if (pth.closed) continue;

        if (pth.pathPoints.length > 4) continue;

        for (j = 0; j < pth.pathPoints.length; j++) {

          var pnt = pth.pathPoints;

          var x   = pnt.anchor[0];

          var y   = pnt.anchor[1];

          if (x <= left || x >= right || y >= top || y <= bott) {

            continue;

          } else {

            continue nextPth;

          }

        }

        pth.remove ();

        rmCount++;

      }

    } catch (e) {

    }

    return rmCount;

  }

  function modEpsSaveOpts (epsSaveOpts) {

    epsSaveOpts.cmykPostScript             = false;

    epsSaveOpts.compatibility              = Compatibility.ILLUSTRATOR10;

    epsSaveOpts.compatibleGradientPrinting = false;

    epsSaveOpts.embedAllFonts              = false;

    epsSaveOpts.embedLinkedFiles           = false;

    epsSaveOpts.flattenOuput               = OutputFlattening.PRESERVEAPPEARANCE;

    epsSaveOpts.includeDocumentThumbnails  = false;

    epsSaveOpts.overprint                  = PDFOverprint.PRESERVEPDFOVERPRINT;

    epsSaveOpts.postScript                 = EPSPostScriptLevelEnum.LEVEL2;

    epsSaveOpts.preview                    = EPSPreview.None;

    epsSaveOpts.saveMultipleArtboards      = false;

  }

  function showAndUnlock () {

    try {

      var d = activeDocument,

          i;

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

        var lay     = d.layers;

        lay.visible = true;

        lay.locked  = false;

        executeMenuCommand ('showAll');

        executeMenuCommand ('unlockAll');

      }

    } catch (e) {

      return false;

    }

    return true;

  }

} ());

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 27, 2016 Oct 27, 2016

Hello o-marat

Thank you for your perfect work.

I have seen, if I manual save files form AI as EPS - I can save the File with the option: "Use Artboards".

In German "Zeichenflächen verwenden":

Bildschirmfoto 2016-10-27 um 10.52.53.png

Is it possible to integrate this step in the script? Maybe at "epsSaveOpts.preview = XYZ"?

I have teste this with:

  1.     epsSaveOpts.preview                    = EPSPreview.BWTIFF; 
  2.     epsSaveOpts.saveMultipleArtboards      = true; 

Now the Script makes two files:

1. An EPS - Preview cropped to object

2. An EPS - Preview cropped to artboard

But I only like to get the File Number 2.

Can you help me a last time? Thank you in advance.

Best regards

Gordian

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 27, 2016 Oct 27, 2016
LATEST

Gordian, hello!

If I understand correctly, you need to add option:

epsSaveOpts.artboardRange = '1';

But the current version of the script must do it New  (sets the size of the artboards along the crop marks (if any, or leave artboard as is)). Or until now not?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines