您当前的位置: 首页 > 

插件开发

暂无认证

  • 3浏览

    0关注

    492博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

illustrator插件--常用功能开发--绘制手提袋--js脚本开发--AI插件

插件开发 发布时间:2022-02-27 12:15:56 ,浏览量:3

  illustrator是矢量编辑软件,画板是绘制处理的重要容器,在印刷方面的一个重要功能就是绘制手提袋,开发一个绘制手提袋功能,以下功能仅用于学习交流,请勿用于非法用途和商业用途,源代码如下所示:

menu();

function menu() {
    var res = "dialog {text: '包袋线', margins: [10,5,10,5], spacing: 8, \n\tPositive: Group {\n\t\tsText: StaticText {text: '正面长:', },\n\t\teText: EditText {preferredSize: [60,20], text: 300, active:1},\n\t\t},\n\tSide: Group {\n\t\tsText: StaticText {text: '侧面宽:', },\n\t\teText: EditText {preferredSize: [60,20], text: '80', },\n\t\t},\n\tBag: Group {\n\t\tsText: StaticText {text: '包袋高:', },\n\t\teText: EditText {preferredSize: [60,20], text: '400', },\n\t\t},\n\tSticky: Group {\n\t\tsText: StaticText {text: '粘口宽:', },\n\t\teText: EditText {preferredSize: [60,20], text: '20', },\n\t\t},\n\tFlap: Group {\n\t\tsText: StaticText {text: '勒口高:', },\n\t\teText: EditText {preferredSize: [60,20], text: '50', },\n\t\t},\n\tBottom: Group {\n\t\tsText: StaticText {text: '下底高:', },\n\t\teText: EditText {preferredSize: [60,20], text: '65', },\n\t\t},\n    Bleed: Group {\n\t\tsText: StaticText {text: '出血宽:', },\n\t\teText: EditText {preferredSize: [60,20], text: '3', },\n\t\t},\n    Eye: Group {\n\t\tsText: StaticText {text: '扣眼距:', },\n\t\teText: EditText {preferredSize: [60,20], text: '110', },\n\t\t},\n\tUnit: Group {\n\t\tsText: StaticText {text: '单  位:', },\n\t\tddL: DropDownList {preferredSize: [60,20], properties:{items:['Pt','派卡','英寸','毫米','厘米','Ha','像素']}, },\n\t\t},\n    eText: EditText {preferredSize: [120,80], properties:{multiline:true} },\n\tcom: Group {\n\t\tBtn: Button {preferredSize: [55,20], text: '确定'},\n\t\tBtn1: Button {preferredSize: [55,20], text: '取消', properties:{name:'cancel'},},\n\t\t},\n\t}";
    bags = new Window(res);
    bags.Unit.ddL.selection = bags.Unit.ddL.items[3];
    var conv = 2.83464566929134;
    bags.eText.text = "大2开手提袋:330mm(长)    90mm(侧面)   450mm(高)\n正2开手提袋:280mm(长)     80mm(侧面)   420mm(高)\n大3开手提袋:250mm(长)     80mm(侧面)   350mm(高)\n正3开手提袋:240mm(长)     80mm(侧面)   290mm(高)\n......";
    var b = {
        positive: Number(bags.Positive.eText.text) * conv,
        side: Number(bags.Side.eText.text) * conv,
        bag_h: Number(bags.Bag.eText.text) * conv,
        sticky: Number(bags.Sticky.eText.text) * conv,
        flap: Number(bags.Flap.eText.text) * conv,
        bottom: Number(bags.Bottom.eText.text) * conv,
        bleed: Number(bags.Bleed.eText.text) * conv,
        eye: Number(bags.Eye.eText.text) * conv,
        all_w: function() {
            return ((this.positive + this.side) * 2) + this.sticky;
        },
        all_h: function() {
            return this.flap + this.bag_h + this.bottom;
        }
    };
    bags.Unit.ddL.onChange = function() {
        conv = unitConv(bags.Unit.ddL.selection);
        bags.Positive.eText.text = b.positive / conv;
        bags.Side.eText.text = b.side / conv;
        bags.Bag.eText.text = b.bag_h / conv;
        bags.Sticky.eText.text = b.sticky / conv;
        bags.Flap.eText.text = b.flap / conv;
        bags.Bottom.eText.text = b.bottom / conv;
        bags.Bleed.eText.text = b.bleed / conv;
        bags.Eye.eText.text = b.eye / conv;
    };
    bags.Positive.eText.onChange = function() {
        b.positive = Number(this.text) * conv;
    };
    bags.Side.eText.onChange = function() {
        b.side = Number(this.text) * conv;
    };
    bags.Side.eText.onChanging = function() {
        bags.Bottom.eText.text = Number(this.text) - (42.5196850393701 / conv);
    };
    bags.Bag.eText.onChange = function() {
        b.bag_h = Number(this.text) * conv;
    };
    bags.Sticky.eText.onChange = function() {
        b.sticky = Number(this.text) * conv;
    };
    bags.Flap.eText.onChange = function() {
        b.flap = Number(this.text) * conv;
    };
    bags.Bottom.eText.onChange = function() {
        b.bottom = Number(this.text) * conv;
    };
    bags.Bleed.eText.onChange = function() {
        b.bleed = Number(this.text) * conv;
    };
    bags.Eye.eText.onChange = function() {
        b.eye = Number(this.text) * conv;
    };
    bags.com.Btn.onClick = function() {
        Bags(b);
        bags.close();
    };
    bags.show();
}

function Bags(b) {
    var doc = app.activeDocument;
    W = b.all_w();
    H = b.all_h();
    newBlack = new GrayColor();
    newBlack.gray = 100;
    creat_layer();

    function creat_layer() {
        var layercheck = 0;
        for (var u = doc.layers.length - 1; u >= 0; u--) {
            var targetLayer = doc.layers[u];
            var layerName = new String(targetLayer.name);
            if (layerName.indexOf("包袋线") == 0) {
                speclayer = doc.layers[u];
                doc.layers[0].visible = true;
                layercheck = 1;
            }
        }
        if (layercheck == 0) {
            speclayer = doc.layers.add();
            speclayer.name = "包袋线";
        }
    }
    speclayer.visible = true;
    speclayerlocked = false;
    var objGroup = speclayer.groupItems.add();
    var rect_GP = objGroup.groupItems.add();
    var line_GP = objGroup.groupItems.add();
    if (app.version.slice(0, 2) >= 14) {
        var padBox = doc.pathItems.rectangle(0, 0, W, H, false);
        padBox.stroked = false;
        doc.artboards[0].artboardRect = padBox.visibleBounds;
        padBox.remove();
    }
    rectangle(rect_GP, b.bleed, -b.bleed, W + (2 * b.bleed), H + (2 * b.bleed));

    function recgroup(bp, bh) {
        rectangle(rect_GP, bp, 0, b.sticky, bh);
        rectangle(rect_GP, bp, b.sticky, b.positive, bh);
        rectangle(rect_GP, bp, b.sticky + b.positive, b.side, bh);
        rectangle(rect_GP, bp, b.sticky + b.positive + b.side, b.positive, bh);
        rectangle(rect_GP, bp, b.sticky + b.side + (b.positive * 2), b.side, bh);
    }
    recgroup(0, b.flap);
    recgroup(-b.flap, b.bag_h);
    recgroup(-b.flap - b.bag_h, b.bottom);

    function ellipseGroup(left) {
        ellipse(rect_GP, -b.flap + 77.9527559055118, left);
        ellipse(rect_GP, -b.flap - 77.9527559055118, left);
    }
    ellipseGroup(b.sticky + ((b.positive - b.eye) / 2));
    ellipseGroup(b.sticky + ((b.positive + b.eye) / 2));
    ellipseGroup(b.sticky + b.positive + b.side + ((b.positive - b.eye) / 2));
    ellipseGroup(b.sticky + b.positive + b.side + ((b.positive + b.eye) / 2));
    line();

    function line() {
        var line = line_GP.pathItems.add();
        setPathStyle(line, [5, 3]);
        line.setEntirePath([
            [(b.sticky + b.positive) - b.bottom, -H],
            [b.sticky + b.positive + (b.side / 2), (b.bottom + (b.side / 2)) - H],
            [b.sticky + b.positive + b.bottom + b.side, -H]
        ]);
        line.duplicate().setEntirePath([
            [0, (b.bottom + b.sticky) - H],
            [b.bottom + b.sticky, -H]
        ]);
        line.duplicate().setEntirePath([
            [b.sticky + b.positive + (b.side / 2), -H],
            [b.sticky + b.positive + (b.side / 2), 0]
        ]);
        line.duplicate().setEntirePath([
            [(b.sticky + (b.positive * 2) + b.side) - b.bottom, -H],
            [b.sticky + (b.positive * 2) + ((b.side * 3) / 2), (b.bottom + (b.side / 2)) - H],
            [b.sticky + (b.positive * 2) + (b.side * 2), b.bottom - H]
        ]);
        line.duplicate().setEntirePath([
            [b.sticky + (b.positive * 2) + ((b.side * 3) / 2), -H],
            [b.sticky + (b.positive * 2) + ((b.side * 3) / 2), 0]
        ]);
        line.duplicate().setEntirePath([
            [b.sticky + b.positive + (b.side / 2), (b.bottom + (b.side / 2)) - H],
            [b.sticky + (b.positive * 2) + ((b.side * 3) / 2), (b.bottom + (b.side / 2)) - H]
        ]);
    }
}

function rectangle(parent, y, x, w, h) {
    var rect = parent.pathItems.rectangle(y, x, w, h);
    setPathStyle(rect, []);
}

function ellipse(parent, top, left) {
    var elli = parent.pathItems.ellipse(top, left, 14.1732283464567, 14.1732283464567, 0, 1);
    setPathStyle(elli, []);
}

function setPathStyle(path, Dash) {
    path.filled = false;
    path.stroked = true;
    path.strokeColor = newBlack;
    path.strokeWidth = 0.25;
    path.strokeOverprint = true;
    path.strokeDashes = Dash;
}

function unitConv(UN) {
    switch (UN) {
        case bags.Unit.ddL.items[0]:
            conv = 1;
            break;
        case bags.Unit.ddL.items[1]:
            conv = 12;
            break;
        case bags.Unit.ddL.items[2]:
            conv = 72;
            break;
        case bags.Unit.ddL.items[3]:
            conv = 2.83464566929134;
            break;
        case bags.Unit.ddL.items[4]:
            conv = 28.3464566929134;
            break;
        case bags.Unit.ddL.items[5]:
            conv = 0.709;
            break;
        case bags.Unit.ddL.items[6]:
            conv = 1;
            break;
        default:

    }
    return conv;
}

  合理的脚本代码可以有效的提高工作效率,减少重复劳动。

文章引用至 作者知了-联系方式1 文章引用至 作者知了-联系方式2

关注
打赏
1665481431
查看更多评论
立即登录/注册

微信扫码登录

0.0426s