0

I was asked to create a small script for Adobe Illustrator CS, which would automatically export project as eps with specific options.

Anywho, I was looking into it this whole morning and came to a brick wall. In adobe's scripting reference I found these methods: EPSSaveOptions or ExportOptionsFlash, ExportOptionsGIF etc. No method for exporting EPS? Note: saving eps is not good, it has to be exported.

So my question is, am I missing something and there is a more comprehensive list of methods which I can't find, or is the only way to accomplish this by coding everything from scratch? I can't really do the latter, cause I'm a designer and not a programmer.

Thank you for your answers in advance.

P.S. The script language doesn't matter much, I just looked into VBS more, but if this can be accomplished with javascript I would be more than happy to make it with js.

MrMag
  • 9
  • 1
  • 3

3 Answers3

1

A similar script already exists.

You could take a look at the source code there if you want to see how it works.

Glitch Desire
  • 14,632
  • 7
  • 43
  • 55
  • You see, that is the problem, like I stated in my question, SAVING as eps is not good, I need to export it. Don't ask why, it's just regulations. And that script uses a different method and different saving options. – MrMag May 14 '13 at 11:13
0

Hi I cannot answer your question completely. But I came here because I needed to batch export wmf files to eps. I found a script at the adobe forum which converts wmf to ai. Combined with your idea to use the eps object EPSSaveOptions, I came up with this working script (for illustrator CC 2015).

I hope this helps others that see this post.

// script.name = makeAiFilesPDFcompatible.jsx;
// script.description = opens and resaves Ai files with PDF compatibility checked (Folder Batch);
// script.requirements = none
// script.parent = CarlosCanto // 06/4/2013;
// script.elegant = false;
// script.forumPost = http://forums.adobe.com/thread/1224874?tstart=0

var folder = Folder.selectDialog("Select Source Folder..."); // select folder

if (folder==null) {
                    alert("Good Bye");
}

else {

    var files = find_files (folder, ['.wmf']);

          var fileCount = files.length; // count them





          if (fileCount>0) {

                    for (i=0; i<fileCount; i++) {

            var idoc = app.open(files[i]);

            var saveOpts = new EPSSaveOptions();

            saveOpts.pdfCompatible = true;

            idoc.saveAs( files[i], saveOpts );

            idoc.close();

                    }

        alert(fileCount + ' file(s) processed');

          }

          else {

                    alert("There are no Illustrator files in this folder.");

          }

}



// 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;

}
Newfarmer
  • 349
  • 2
  • 9
  • 1
    I modified your script a little bit to be more user friendly - see [github](https://gist.github.com/ondrejtichacek/2bc3bf77f0e2003935f3cdf789738726) – Ondrian Mar 31 '18 at 21:12
0

This one exports every layer to an eps with options. Isolate the function saveEPS and I suppose that's what you need.

var doc = app.activeDocument;
var docname = (doc.name.split('.'))[0]; // name
var doc_artboard = doc.artboards[0].artboardRect;

if (app.documents.length > 1) {
        alert( "Nur ein Dokument darf geöffnet sein. Schließen Sie andere Dokumente und führen Sie das Script erneut aus.");
} else {

    var ok = confirm( "Bitte speichern Sie zuerst Ihr Original.\nDie Ebenen werden im gleichen Ordner wie Ihre Datei gespeichert.\nWeiter?" );

    if (ok) {

        // prepare layers
        for(var i=0; i<doc.layers.length; i++) {
            doc.layers[i].visible = false;
        }

        // go through each layers
        for(var i=0; i<doc.layers.length; i++) {
            app.activeDocument = doc;

            if (i>0) doc.layers[i-1].visible = false;
            doc.layers[i].visible = true;
            doc.activeLayer = doc.layers[i];

            saveEPS( doc.path, doc.activeLayer.name, i );
        }

        // close original file without saving
        doc.close( SaveOptions.DONOTSAVECHANGES );

    }

}

function saveEPS( path, name, id ) {

    var currlayer = doc.layers[id]; 
    var g = currlayer.groupItems.add();
    group( g, currlayer.pageItems );    

    var t = g.top;
    var l = g.left;

    var w = doc.width;
    var h = doc.height;

    /*
    var w = 31.1*2.834645;
    var h = 28.15*2.834645;
    */

    var myPreset = new DocumentPreset;
    myPreset.width = w;
    myPreset.height = h;
    myPreset.units = RulerUnits.Millimeters;
    myPreset.title = docname;
    var newdoc = documents.addDocument( "Druck", myPreset);
    /*
    var newdoc = app.documents.add ( doc.documentColorSpace, doc.width, doc.height, 1,
    DocumentArtboardLayout.Row, 72); 
    */
    newdoc.artboards[0].artboardRect = doc_artboard;
    var newlayer = newdoc.layers[0];

    g.duplicate( newlayer, ElementPlacement.PLACEATBEGINNING );
    newlayer.pageItems[0].top = t;
    newlayer.pageItems[0].left = l;

    path.changePath( name+".eps" );

    var saveOpts = new EPSSaveOptions();
    saveOpts.compatibility = Compatibility.ILLUSTRATOR16;
    saveOpts.embedLinkedFiles = true;
    saveOpts.includeDocumentThumbnails = true;
    saveOpts.embedAllFonts = true;
    saveOpts.saveMultipleArtboards = false;
    saveOpts.cmykPostScript = true;
    saveOpts.preview = EPSPreview.TRANSPARENTCOLORTIFF; 

    newdoc.saveAs( path, saveOpts );
    newdoc.close( SaveOptions.DONOTSAVECHANGES );   

    // wait for the new file to save and close before continue.
    // A callback function (if possible) will be better than a while loop for sure.
    while (app.documents.length > 1) {
        continue;
    }
}

function group( gg, items ) {

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

        if (items[i]!=gg) { 
            newItem = items[i].move (gg, ElementPlacement.PLACEATBEGINNING);
        }
    }
    return newItem;
}
AndyWizz
  • 113
  • 8