Illustrator JavaScript 出血

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值