[英]Batch Export Symbols to SVG - Illustrator
題:
我創建了一個腳本,它遍歷 Illustrator 文檔中的所有符號並將它們導出為 PNG。
我也需要它為 SVG 工作,但是,這並不像更改文件類型那么簡單。
由於 Illustrator 將最近保存的 svg app.activeDocument
的默認行為, for
循環為每個符號嵌套了新目錄。
例如
exports/
symbol01.svg
exports/
symbol02.svg
exports/
symbol03.svg
etc..
我很確定問題出在//create directory
和//choose directory
,但我終生無法弄清楚。
var doc = app.activeDocument;
var symbolCount = doc.symbols.length;
if (symbolCount >= 1) {
if (confirm("Are all your layers hidden?")) {
// create temp layer
doc.layers.add();
for (var i = 0; i < doc.symbols.length; i++) {
// place a symbol instance - temp
var s = doc.symbolItems.add(doc.symbols[i]);
// create directory
var dest = new Folder(doc.path + "/exports");
if (!dest.exists) dest.create();
// choose directory
dest.changePath(doc.symbols[i].name);
// export symbols
saveSVG(dest);
// delete temp symbol instance
s.remove();
}
// remove temp layer
doc.layers[0].remove();
}
function saveSVG(file) {
// save options
var type = ExportType.SVG;
var options = new ExportOptionsSVG();
// export
doc.exportFile(file, type, options);
}
} else {
alert("You don't have any symbols in this document");
}
有一種存儲初始app.activeDocument
方法可能會解決這個問題,但我不知道如何做到這一點..如果這是最好的方法嗎?
獎金:
這個腳本的另一個問題是畫板沒有根據符號調整大小,所以我找到了一個函數fitArtboardToSelectedArt()
我已經嘗試實現但沒有成功..誰能解釋它應該如何工作?
附注。 這是 Illustrator 腳本文檔的鏈接: http : //adobe.ly/1JxLlUK
弄清楚了 :)
如果您需要這樣做,請隨意使用以下腳本。
/*
* Export Symbols as SVGs - Illustrator
* --------------------------------------
* Created By Shane Parsons - 30PT Design Inc.
* http://30ptdesign.com/
*/
var doc = app.activeDocument;
var symbolCount = doc.symbols.length;
if (symbolCount >= 1) {
if (confirm("Are all your layers hidden?")) {
// choose directory
var dest = Folder(doc.path).selectDlg();
// folder chosen
if (dest) {
// create temp layer
doc.layers.add();
// create temp artboard
doc.artboards.add(doc.artboards[0].artboardRect);
// get temp artboard
var tempAB = doc.artboards.getActiveArtboardIndex();
// loop through symbols
for (var i = 0; i < doc.symbols.length; i++) {
// place a symbol instance - temp
var symbol = doc.symbolItems.add(doc.symbols[i]);
// resize artboard
doc.artboards[tempAB].artboardRect = doc.visibleBounds;
app.redraw();
// choose directory
var filename = doc.symbols[i].name;
// export symbols
saveSVG(dest, filename);
// delete temp symbol instance
symbol.remove();
}
// remove temp layer
doc.layers[0].remove();
// remove temp artboard
doc.artboards[tempAB].remove();
}
}
function saveSVG(dest, filename) {
// save options
var type = ExportType.SVG;
var options = new ExportOptionsSVG();
// file
var file = new File(dest + "/" + filename);
// export
doc.exportFile(file, type, options);
}
} else {
alert("You don't have any symbols in this document");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.