aijs 添加矩形 添加线条

以下是帮助你 完成任务的一些 命令

var doc = app.activeDocument;
var pt = 72 / 25.4
//以下是测试代码
// artboard = Artboard(1)
// //获取原点坐标(画板左上角)
// x = artboard.left;
// y = artboard.top;
// artboard_width = artboard.width;
// artboard_height = artboard.height;

// // 绝对值添加
// add_line(x, y, 30, 30, '', 'abs')


// // 相对值添加
// add_line(x, y, 30, 0)

// // 与画板同尺寸添加一个 描边0
// add_rect(x, y, artboard_width, artboard_height, 0, 0, createColor('nocolor'), createColor('nocolor'))
// // 比画板 大3mm 尺寸添加一个 描边0.1


// add_rect(x, y, artboard_width, artboard_height, 0.1, 3*pt, createColor('nocolor'), createColor('nocolor'))

// add_rect(0, 0, 100, 100)
// add_rect(0, 0, 100, 100,0.1,0,createColor('',100,0,0,0),createColor('',0,100,0,0))
function add_rect(x, y, width, height, line_width, expand_size, fill_color, stroke_color) {
    /**
     * 添加一个矩形 
     * (x,y) 左上角坐标(必填)
     * (width,height)尺寸(必填)
     * line_width 描边(默认0)
     * expand_size 外扩尺寸(默认0)
     * fill_color 填充色(默认随系统设置)
     * stroke_color 描边色(默认随系统设置)
     * 
     * 例子
     * 最简单的例子 
     * add_rect(0, 0, 100, 100)
     * 最全的例子
     * add_rect(0, 0, 100, 100,0.1,0,createColor('',100,0,0,0),createColor('',0,100,0,0))
     */
    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) {
    /**
     * 两点确定一个坐标
     * (x1,y1) (x2,y2) (必填)
     * line_width:默认为0.1mm
     * position:(默认相对) relative 与 abs
     *      relative 表示第二点 的坐标是相对于第一点的
     *      abs 表示第二点 是绝对值
     * stroke_color:描边颜色
     * 
     * 例子
     * add_line(0,0,30,30,'','abs')
     * add_line(0,0,30,0)
     */
    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 (非必填 默认当前画板)
     * 画板类用于获取画板的属性
     * 宽度,高度,坐标(上下左右垂直中,水平中),简单的信息
     * 
     * 例子
     * artboard = Artboard()
     * artboard = Artboard(0)
     */
    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) {
    /**
     * color_type (必填 '','cmyk','pt','nocolor' 四选一)
     * c, m, y, k, ptname, ptinit 非必填
     * 
     * 例子
     * 创建黑色
     * createColor('',0,0,0,100)
     * 创建红色
     * createColor('',0,100,100,0)
     * 创建无色
     * createColor('nocolor')
     */
    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()
// 打印 信息
// alert(artboard.info)
//获取原点坐标(画板左上角)
x = artboard.left;
y = artboard.top;
//获取画板宽度 高度
artboard_width = artboard.width;
artboard_height = artboard.height;
//添加 一个与画板 同尺寸的矩形 描边0.5
add_rect(x, y, artboard_width, artboard_height, 0.5*pt, 0*pt,createColor('nocolor'),createColor('',100,0,0,0))
//添加 一个与画板 大3 的矩形 描边0.5
add_rect(x, y, artboard_width, artboard_height, 0.5*pt, 3*pt,createColor('nocolor'),createColor('',0,100,0,0))
//添加 一个与画板 小3 的矩形 描边0.5
add_rect(x, y, artboard_width, artboard_height, 0.5*pt, -3*pt,createColor('nocolor'),createColor('',0,0,100,0))
//添加 一条线 描边0.5 position:(默认相对) relative 与 abs
add_line(x-3*pt, y, artboard_width+6*pt, 0,0.5*pt,'relative',createColor('',100,100,0,0))
//添加 一条线 距离画板顶部20mm 描边0.5 position:(默认相对) relative 与 abs
add_line(x-3*pt, y-20*pt, artboard_width+6*pt, 0,0.5*pt,'relative',createColor('',100,100,0,0))
//添加 一条线 距离画板底部20mm 描边0.5 position:(默认相对) relative 与 abs
add_line(x-3*pt, y-artboard_height+20*pt, artboard_width+6*pt, 0,0.5*pt,'relative',createColor('',100,100,0,0))

//添加 一条线 距离画板左边20mm 描边0.5 position:(默认相对) relative 与 abs
add_line(x+20*pt, y+3*pt,0, artboard_height+6*pt,0.5*pt,'relative',createColor('',100,100,0,0))
//添加 一条线 距离画板底部20mm 描边0.5 position:(默认相对) relative 与 abs
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)
    // 打印 信息
    // alert(artboard.info)
    //获取原点坐标(画板左上角)
    x = artboard.left;
    y = artboard.top;
    //获取画板宽度 高度
    artboard_width = artboard.width;
    artboard_height = artboard.height;
    //添加 一个与画板 同尺寸的矩形 描边0.5
    add_rect(x, y, artboard_width, artboard_height, 0.5 * pt, 0 * pt, createColor('nocolor'), createColor('', 100, 0, 0, 0))
    //添加 一个与画板 大3 的矩形 描边0.5
    add_rect(x, y, artboard_width, artboard_height, 0.5 * pt, 3 * pt, createColor('nocolor'), createColor('', 0, 100, 0, 0))
    //添加 一个与画板 小3 的矩形 描边0.5
    add_rect(x, y, artboard_width, artboard_height, 0.5 * pt, -3 * pt, createColor('nocolor'), createColor('', 0, 0, 100, 0))
    //添加 一条线 描边0.5 position:(默认相对) relative 与 abs
    add_line(x - 3 * pt, y, artboard_width + 6 * pt, 0, 0.5 * pt, 'relative', createColor('', 100, 100, 0, 0))
    //添加 一条线 距离画板顶部20mm 描边0.5 position:(默认相对) relative 与 abs
    add_line(x - 3 * pt, y - 20 * pt, artboard_width + 6 * pt, 0, 0.5 * pt, 'relative', createColor('', 100, 100, 0, 0))
    //添加 一条线 距离画板底部20mm 描边0.5 position:(默认相对) relative 与 abs
    add_line(x - 3 * pt, y - artboard_height + 20 * pt, artboard_width + 6 * pt, 0, 0.5 * pt, 'relative', createColor('', 100, 100, 0, 0))

    //添加 一条线 距离画板左边20mm 描边0.5 position:(默认相对) relative 与 abs
    add_line(x + 20 * pt, y + 3 * pt, 0, artboard_height + 6 * pt, 0.5 * pt, 'relative', createColor('', 100, 100, 0, 0))
    //添加 一条线 距离画板底部20mm 描边0.5 position:(默认相对) relative 与 abs
    add_line(x + artboard_width - 20 * pt, y + 3 * pt, 0, artboard_height + 6 * pt, 0.5 * pt, 'relative', createColor('', 100, 100, 0, 0))
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值