這個將每個圖層導出到帶有選項的eps。 分離函數saveEPS,我想這就是你需要的。
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;
}
你看,這就是問題,就像我在我的問題中說的那樣,因爲EPS保存不好,我需要導出它。不要問爲什麼,這只是法規。該腳本使用不同的方法和不同的保存選項。 – MrMag 2013-05-14 11:13:37