illustrator脚本 画板信息函数

获取画板信息函数

var doc = app.activeDocument;
var pt = 72 / 25.4
function Artboard(index) {

    /**
     * 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.info = '当前是第' + index + '个页面\n页面尺寸为' + this.width / pt + 'x' + this.height / pt + ' mm'
    return this;
}

var artboard = Artboard(0);

alert(artboard.info)

你可能感兴趣的:(illustrator插件,javascript,illustrator)