这是一个在画板上自动生成辅助线和角线的脚本,只要单击最右边按钮运行脚本即可。
绿色的为参考线及出血线。
#target "Illustrator"
var settings = {'addTrim' : true,'addBleedGuide' : true,'addCenterGuide' : true,'addCover' : false,'overlapAlert' : false,'trimmarks_layername' : "[Trim marks]",'guides_layername' : "[Guides]",'cover_layername' : "[Cover]",'cover_color' : {"R":93, "G":93, "B":93}
};const MM_PX = 2.83466666666667;
const SCRIPT_TITLE = "添加角线和裁切标记";
const SCRIPT_VERSION = "0.7";
var board = activeDocument;
var doc = app.activeDocument;
var bds = {"x":0, "y":0, "w":0, "h":0};var dlgpos = {'x':150, 'y':50, 'w':320, 'h':480};
var dlg = new Window('dialog', SCRIPT_TITLE + " - ver." + SCRIPT_VERSION, [dlgpos.x, dlgpos.y, dlgpos.x+dlgpos.w, dlgpos.y+dlgpos.h]);
dlg.cancelButton = dlg.add("button", [dlgpos.w/2-105, dlgpos.h-60, (dlgpos.w/2-105)+100, (dlgpos.h-60)+25], "取消", {name: "cancel"});
dlg.okButton = dlg.add("button", [dlgpos.w/2+5, dlgpos.h-60, (dlgpos.w/2+5)+100, (dlgpos.h-60)+25], "执行", { name:"ok"});dlg.btnPnl = dlg.add("panel",[20,15,300,110],"裁切标记:");
dlg.checkBox1 = dlg.add("checkbox",[35,40,290,40+20], "添加裁切标记");
dlg.label1 = dlg.add("statictext",[35,73,100,73+20], "图层名称:");
dlg.textField1 = dlg.add("edittext",[100,70,280,70+20], settings.trimmarks_layername);dlg.btnPnl = dlg.add("panel",[20,125,300,245],"辅助线:");
dlg.checkBox2 = dlg.add("checkbox",[35,150,400,150+20], "添加辅助线");
dlg.checkBox3 = dlg.add("checkbox",[35,175,400,175+20], "在中心添加辅助线");
dlg.label2 = dlg.add("statictext",[35,208,100,208+20], "图层名称:");
dlg.textField2 = dlg.add("edittext",[100,205,270,205+20], settings.guides_layername);dlg.btnPnl = dlg.add("panel",[20,260,300,350],"画板矩形:");
dlg.checkBox4 = dlg.add("checkbox",[35,285,400,285+20], "外部遮罩");
dlg.label3 = dlg.add("statictext",[35,318,100,318+20], "图层名称:");
dlg.textField3 = dlg.add("edittext",[100,315,270,315+20], settings.cover_layername);dlg.checkBox5 = dlg.add("checkbox",[20,370,400,370+20], "忽略图层名称重复警告");dlg.checkBox1.value = settings.addTrim;
dlg.checkBox2.value = settings.addBleedGuide;
dlg.checkBox3.value = settings.addCenterGuide;
dlg.checkBox4.value = settings.addCover;
dlg.checkBox5.value = settings.overlapAlert;dlg.okButton.onClick = function() {dlg.close();boilerplate();
}
dlg.cancelButton.onClick = function() {dlg.close();
}
dlg.show();function addTrimmarks() {var trimmarks_data = [[[-MM_PX*3, MM_PX*12], [-MM_PX*3, 0], [-MM_PX*12, 0]],[[0, MM_PX*12], [0, MM_PX*3], [-MM_PX*12, MM_PX*3]],[[bds.w+MM_PX*3, MM_PX*12], [bds.w+MM_PX*3, 0], [bds.w+MM_PX*12, 0]],[[bds.w, MM_PX*12], [bds.w, MM_PX*3], [bds.w+MM_PX*12, MM_PX*3]],[[-MM_PX*3, -bds.h-MM_PX*12], [-MM_PX*3, -bds.h], [-MM_PX*12, -bds.h]],[[0, -bds.h-MM_PX*12], [0, -bds.h-MM_PX*3], [-MM_PX*12, -bds.h-MM_PX*3]],[[bds.w+MM_PX*3, -bds.h-MM_PX*12], [bds.w+MM_PX*3, -bds.h], [bds.w+MM_PX*12, -bds.h]],[[bds.w, -bds.h-MM_PX*12], [bds.w, -bds.h-MM_PX*3], [bds.w+MM_PX*12, -bds.h-MM_PX*3]],[[bds.w/2, MM_PX*(4.23+8.467)], [bds.w/2, MM_PX*4.23]],[[(bds.w/2)-(MM_PX*25.4/2), MM_PX*6.35], [(bds.w/2)+(MM_PX*25.4/2), MM_PX*6.35]],[[bds.w/2, -bds.h-MM_PX*(4.23+8.467)], [bds.w/2, -bds.h-MM_PX*4.23]],[[(bds.w/2)-(MM_PX*25.4/2), -bds.h-MM_PX*6.35], [(bds.w/2)+(MM_PX*25.4/2), -bds.h-MM_PX*6.35]],[[-MM_PX*(4.23+8.467), -bds.h/2], [-MM_PX*4.23, -bds.h/2]],[[-MM_PX*6.35, -bds.h/2+(MM_PX*25.4/2)], [-MM_PX*6.35, -bds.h/2-(MM_PX*25.4/2)]],[[bds.w+MM_PX*(4.23+8.467), -bds.h/2], [bds.w+MM_PX*4.23, -bds.h/2]],[[bds.w+MM_PX*6.35, -bds.h/2+(MM_PX*25.4/2)], [bds.w+MM_PX*6.35, -bds.h/2-(MM_PX*25.4/2)]]];var trimLayer;try {trimLayer = doc.layers.getByName(settings.trimmarks_layername);} catch(e) {trimLayer = doc.layers.add();trimLayer.name = settings.trimmarks_layername;}trimLayer.locked = false;trimLayer.visible = true;doc.activeLayer = trimLayer;var trimPaths = new Array();for (i=0; i<trimmarks_data.length; i++) {trimPaths[i] = trimLayer.pathItems.add();trimPaths[i].setEntirePath(trimmarks_data[i]);trimPaths[i].filled = false;trimPaths[i].stroked = true;trimPaths[i].strokeWidth = 0.3;try {trimPaths[i].strokeColor = doc.swatches["[注册]"].color;} catch (e) {trimPaths[i].strokeColor = getCMYK(100,100,100,100);}}
}function addBleedGuides() {var guideLayer;try {guideLayer = doc.layers.getByName(settings.guides_layername);} catch(e) {guideLayer = doc.layers.add();guideLayer.name = settings.guides_layername;}guideLayer.locked = false;guideLayer.visible = true;doc.activeLayer = guideLayer;var guidePaths = new Array();if (settings.addBleedGuide) {guidePaths.push(guideLayer.pathItems.rectangle(MM_PX*3, -MM_PX*3, bds.w+MM_PX*6, bds.h+MM_PX*6));guidePaths.push(guideLayer.pathItems.rectangle(0, 0, bds.w, bds.h));}if (settings.addCenterGuide) {guidePaths.push(guideLayer.pathItems.add());guidePaths[guidePaths.length-1].setEntirePath([[bds.w/2, MM_PX*50], [bds.w/2, -bds.h-MM_PX*50]]);guidePaths.push(guideLayer.pathItems.add());guidePaths[guidePaths.length-1].setEntirePath([[-MM_PX*50, -bds.h/2], [bds.w+MM_PX*50, -bds.h/2]]);}for (i=0; i<guidePaths.length; i++) {guidePaths[i].translate(bds.x, bds.y);guidePaths[i].filled = false;guidePaths[i].stroked = false;guidePaths[i].guides = true;}}function addCover() {var coverLayer;try {coverLayer = doc.layers.getByName(settings.cover_layername);} catch(e) {coverLayer = doc.layers.add();coverLayer.name = settings.cover_layername;}coverLayer.locked = false;coverLayer.visible = true;doc.activeLayer = coverLayer;var coverPaths = new Array();coverPaths.push(coverLayer.pathItems.rectangle(MM_PX*100, -MM_PX*100, MM_PX*100, bds.h+MM_PX*200));coverPaths.push(coverLayer.pathItems.rectangle(MM_PX*100, bds.w, MM_PX*100, bds.h+MM_PX*200));coverPaths.push(coverLayer.pathItems.rectangle(MM_PX*100, -MM_PX*100, bds.w+MM_PX*200, MM_PX*100));coverPaths.push(coverLayer.pathItems.rectangle(-bds.h, -MM_PX*100, bds.w+MM_PX*200, MM_PX*100));for (i=0; i<coverPaths.length; i++) {coverPaths[i].translate(bds.x, bds.y);coverPaths[i].filled = true;coverPaths[i].stroked = false;coverPaths[i].fillColor = getRGB(settings.cover_color.R, settings.cover_color.G, settings.cover_color.B);}
}function getCMYK(c,m,y,k) {cmykColor = new CMYKColor();cmykColor.cyan = c;cmykColor.magenta = m;cmykColor.yellow = y;cmykColor.black = k;return cmykColor;
}
function getRGB(r,g,b) {rgbColor = new RGBColor();rgbColor.red = r;rgbColor.green = g;rgbColor.blue = b;return rgbColor;
}
function getSpotColor(colorName) {spotColor = new SpotColor();spotColor.name = colorName;return spotColor;
}function boilerplate(){var ab = doc.artboards[doc.artboards.getActiveArtboardIndex()];bds.x = ab.artboardRect[0];bds.y = ab.artboardRect[1];bds.w = ab.artboardRect[2] - bds.x;bds.h = -(ab.artboardRect[3] - bds.y);var startLayerName = doc.activeLayer.name;if (dlg.textField1.text != "" ) settings.trimmarks_layername = dlg.textField1.text;if (dlg.textField2.text != "" ) settings.guides_layername = dlg.textField2.text;if (dlg.textField3.text != "" ) settings.cover_layername = dlg.textField3.text;settings.addTrim = dlg.checkBox1.value;settings.addBleedGuide = dlg.checkBox2.value;settings.addCenterGuide = dlg.checkBox3.value;settings.addCover = dlg.checkBox4.value;settings.overlapAlert = dlg.checkBox5.value;var ms = ' 图层名称重复,是否继续';try {var tl = doc.layers.getByName(settings.trimmarks_layername);} catch(e) {} finally {if (tl && settings.addTrim && !settings.overlapAlert) {if (!confirm(settings.trimmarks_layername + ms)) return false;}}try {var gl = doc.layers.getByName(settings.guides_layername);} catch(e) {} finally {if (gl && (settings.addBleedGuide || settings.addCenterGuide) && !settings.overlapAlert) {if (!confirm(settings.guides_layername + ms)) return false;}}try {var cl = doc.layers.getByName(settings.cover_layername);} catch(e) {} finally {if (cl && settings.addCover && !settings.overlapAlert) {if (!confirm(settings.cover_layername + ms)) return false;}}if (settings.addCover) addCover();if (settings.addTrim) addTrimmarks();if (settings.addBleedGuide || settings.addCenterGuide) addBleedGuides();try {cl = doc.layers.getByName(settings.cover_layername);cl.locked = false;doc.activeLayer = cl;if (cl.zOrderPosition < doc.layers.length) {cl.zOrder(ZOrderMethod.BRINGTOFRONT);}cl.locked = true;} catch(e) {}try {tl = doc.layers.getByName(settings.trimmarks_layername);tl.locked = false;doc.activeLayer = tl;if (tl.zOrderPosition < doc.layers.length) {tl.zOrder(ZOrderMethod.BRINGTOFRONT);}tl.locked = true;} catch(e) {}try {gl = doc.layers.getByName(settings.guides_layername);gl.locked = false;doc.activeLayer = gl;if (gl.zOrderPosition < doc.layers.length) {gl.zOrder(ZOrderMethod.BRINGTOFRONT);}} catch(e) {}doc.activeLayer = doc.layers.getByName(startLayerName);}