Illustrator JavaScript 出血
var doc = app.activeDocument;
var pt = 72/25.4;
var rc = 1*pt;
var ls = 6*pt;
for(var i =0;i<doc.selection.length;i++){
var shape = doc.selection[i];
var art = Artboard();
var left = isRC(art.left,shape.left,rc,'left');
var bottom = isRC(art.bottom,shape.top-shape.height,rc,'bottom');
var right = isRC(art.right,shape.left+shape.width,rc,'right');
var top = isRC(art.top,shape.top,rc,'top');
if(left){
shape.width = shape.width+ls;
shape.left =shape.left -ls;
}
if(right){
shape.width = shape.width+ls;
}
if(bottom){
shape.height = shape.height+ls;
}
if(top){
shape.height = shape.height+ls;
shape.top =shape.top +ls;
}
}
function isRC(a,b,rc,index){
if(index=='left')return a>b||Math.abs(a-b)<=rc;
if(index=='top')return a<b||Math.abs(a-b)<=rc;
if(index=='right')return a<b||Math.abs(a-b)<=rc;
if(index=='bottom')return a>b||Math.abs(a-b)<=rc;
return Math.abs(a-b)<=rc;
}
function Artboard(index) {
var doc = app.activeDocument;
/**
* index 下标 (非必填 默认当前画板)
* 画板类用于获取画板的属性
* 宽度,高度,坐标(上下左右垂直中,水平中),简单的信息
*
* 例子
* artboard = Artboard()
* artboard = Artboard(0)
* 打印信息
* alert(artboard.info)
*/
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.artboard = doc.artboards[index];
this.abBounds = abBounds;
this.index = index;
this.info = '当前是第' + index + '个页面\n页面尺寸为' + this.width / pt + 'x' + this.height / pt + ' mm'
return this;
}