以下是帮助你 完成任务的一些 命令
var doc = app.activeDocument;
var pt = 72 / 25.4
function add_rect(x, y, width, height, line_width, expand_size, fill_color, stroke_color) {
line_width = line_width == undefined ? 0 : line_width
expand_size = expand_size == undefined ? 0 : expand_size
rect = doc.pathItems.rectangle(y + expand_size, x - expand_size, width + expand_size * 2, height + expand_size * 2);
rect.strokeWidth = line_width;
if (line_width>0&&stroke_color != undefined) rect.strokeColor = stroke_color;
if (fill_color != undefined) rect.fillColor = fill_color;
}
function add_line(x1, y1, x2, y2, line_width, position, stroke_color) {
position = position == undefined ? 'relative' : position
line_width = line_width == undefined || line_width == '' ? 0.1 * pt : line_width
line = doc.pathItems.add();
if (position == 'relative') {
line.setEntirePath([[x1, y1], [x1 + x2, y1 - y2]]);
} else {
line.setEntirePath([[x1, y1], [x2, y2]]);
}
if (stroke_color != undefined && stroke_color != '') {
line.strokeColor = stroke_color;
}
line.strokeWidth = line_width;
}
function Artboard(index) {
index = index == undefined ? doc.artboards.getActiveArtboardIndex() : index
var abBounds = doc.artboards[index].artboardRect;
this.width = abBounds[2] - abBounds[0];
this.height = abBounds[1] - abBounds[3];
this.left = abBounds[0];
this.top = abBounds[1];
this.bottom = abBounds[3];
this.right = abBounds[2];
this.centerX = this.left + this.width / 2;
this.centerY = this.bottom + this.height / 2;
this.info = '当前是第' + index + '个页面\n页面尺寸为' + this.width / pt + 'x' + this.height / pt + ' mm'
return this;
}
function createColor(color_type, c, m, y, k, ptname, ptinit) {
if (color_type == '' || color_type == 'cmyk') {
var cmykColor = new CMYKColor();
cmykColor.cyan = c;
cmykColor.magenta = m;
cmykColor.yellow = y;
cmykColor.black = k;
return cmykColor;
} else if (color_type == 'pt') {
} else if (color_type == 'nocolor') {
return new NoColor();
}
}
当前激活画板添加矩形与线段
#include "jialan75_utils.js";
artboard = Artboard()
x = artboard.left;
y = artboard.top;
artboard_width = artboard.width;
artboard_height = artboard.height;
add_rect(x, y, artboard_width, artboard_height, 0.5*pt, 0*pt,createColor('nocolor'),createColor('',100,0,0,0))
add_rect(x, y, artboard_width, artboard_height, 0.5*pt, 3*pt,createColor('nocolor'),createColor('',0,100,0,0))
add_rect(x, y, artboard_width, artboard_height, 0.5*pt, -3*pt,createColor('nocolor'),createColor('',0,0,100,0))
add_line(x-3*pt, y, artboard_width+6*pt, 0,0.5*pt,'relative',createColor('',100,100,0,0))
add_line(x-3*pt, y-20*pt, artboard_width+6*pt, 0,0.5*pt,'relative',createColor('',100,100,0,0))
add_line(x-3*pt, y-artboard_height+20*pt, artboard_width+6*pt, 0,0.5*pt,'relative',createColor('',100,100,0,0))
add_line(x+20*pt, y+3*pt,0, artboard_height+6*pt,0.5*pt,'relative',createColor('',100,100,0,0))
add_line(x+artboard_width-20*pt, y+3*pt,0, artboard_height+6*pt,0.5*pt,'relative',createColor('',100,100,0,0))
每个画板都加
#include "jialan75_utils.js";
for (i = 0; i < doc.artboards.length; i++) {
artboard = Artboard(i)
x = artboard.left;
y = artboard.top;
artboard_width = artboard.width;
artboard_height = artboard.height;
add_rect(x, y, artboard_width, artboard_height, 0.5 * pt, 0 * pt, createColor('nocolor'), createColor('', 100, 0, 0, 0))
add_rect(x, y, artboard_width, artboard_height, 0.5 * pt, 3 * pt, createColor('nocolor'), createColor('', 0, 100, 0, 0))
add_rect(x, y, artboard_width, artboard_height, 0.5 * pt, -3 * pt, createColor('nocolor'), createColor('', 0, 0, 100, 0))
add_line(x - 3 * pt, y, artboard_width + 6 * pt, 0, 0.5 * pt, 'relative', createColor('', 100, 100, 0, 0))
add_line(x - 3 * pt, y - 20 * pt, artboard_width + 6 * pt, 0, 0.5 * pt, 'relative', createColor('', 100, 100, 0, 0))
add_line(x - 3 * pt, y - artboard_height + 20 * pt, artboard_width + 6 * pt, 0, 0.5 * pt, 'relative', createColor('', 100, 100, 0, 0))
add_line(x + 20 * pt, y + 3 * pt, 0, artboard_height + 6 * pt, 0.5 * pt, 'relative', createColor('', 100, 100, 0, 0))
add_line(x + artboard_width - 20 * pt, y + 3 * pt, 0, artboard_height + 6 * pt, 0.5 * pt, 'relative', createColor('', 100, 100, 0, 0))
}