Illustrator腳本開發(fā)畫板劃分-源碼
發(fā)布時(shí)間:2024-11-08 11:44 [ 我要自學(xué)網(wǎng)原創(chuàng) ] 發(fā)布人: 快樂小女 閱讀: 111

var win = new Window("dialog", "畫板劃分Pro");
win.location = [100, 100];
var msgPnl = win.add("panel", undefined, "選項(xiàng)");
msgPnl.add("StaticText", undefined, "請(qǐng)輸入正整數(shù)!");
var g = msgPnl.add("group", undefined);
g.add("StaticText", undefined, "左右劃分");
var myX = g.add("EditText", [0, 0, 60, 20], "2");
g.add("StaticText", undefined, "上下劃分");
var myY = g.add("EditText", [0, 0, 60, 20], "1");
msgPnl.add("StaticText", undefined, "免責(zé)聲明:文件壞了不賠!");
msgGrp = win.add("group", undefined, "Group");
var BtnOK = msgGrp.add("button", undefined, "確定", {
    name: "ok"
});
var BtnCancel = msgGrp.add("button", undefined, "取消", {
    name: "cancel"
});
msgGrp.alignment = [ScriptUI.Alignment.CENTER, ScriptUI.Alignment.TOP];
myX.helpTip = "請(qǐng)?zhí)钊胝麛?shù)!填別的后果自負(fù)!";
myY.helpTip = "請(qǐng)?zhí)钊胝麛?shù)!填別的后果自負(fù)!";
myX.onChange = function() {
    var theText = Number(this.text);
    if (theText < 1) {
        this.text = 1;
        win.show();
    }
};
myY.onChange = function() {
    var theText = Number(this.text);
    if (theText < 1) {
        this.text = 1;
        win.show();
    }
};
BtnOK.onClick = function() {
    var w = myX.text;
    var h = myY.text;
    main(w, h);
    win.close(0);
};
BtnCancel.onClick = function() {
    win.close();
};
win.show();

function main(w, h) {
    var myDoc = activeDocument;
    var N = myDoc.artboards.length;
    var Arts = myDoc.artboards;
    var x = w;
    var y = h;
    for (var n = 0; n < N; n += 1) {
        var left = Arts[n].artboardRect[0];
        var top = Arts[n].artboardRect[1];
        var right = Arts[n].artboardRect[2];
        var bottom = Arts[n].artboardRect[3];
        var theWidth = right - left;
        var theHeight = top - bottom;
        var newWidth = theWidth / x;
        var newHeight = theHeight / y;
        var newRight = left + newWidth;
        var newBottom = top - newHeight;
        var newArtboards = myDoc.artboards.add([left, top, newRight, newBottom]);
        var p1 = newArtboards;
        var p2 = newArtboards;
        for (var j = 0; j < y; j += 1) {
            for (var i = 0; i < x - 1; i += 1) {
                p1 = addPage(p1, myDoc);
            }
            if (j < (y - 1)) {
                p2 = addPageB(p2, myDoc);
                p1 = p2;
            }
        }
    }
    for (var n = 0; n < N; n += 1) {
        myDoc.artboards.remove(0);
    }
}

function addPage(Page, Doc) {
    var myRec = Page.artboardRect;
    var L = myRec[0];
    var T = myRec[1];
    var R = myRec[2];
    var B = myRec[3];
    var W = R - L;
    L += W;
    R += W;
    var art = Doc.artboards.add([L, T, R, B]);
    return art;
}

function addPageB(Page, Doc) {
    var myRec = Page.artboardRect;
    var L = myRec[0];
    var T = myRec[1];
    var R = myRec[2];
    var B = myRec[3];
    var H = B - T;
    T += H;
    B += H;
    var art = Doc.artboards.add([L, T, R, B]);
    return art;
}

Illustrator腳本開發(fā)教程
我要自學(xué)網(wǎng)商城 ¥70 元
進(jìn)入購買
文章評(píng)論
0 條評(píng)論 按熱度排序 按時(shí)間排序 /350
添加表情
遵守中華人民共和國(guó)的各項(xiàng)道德法規(guī),
承擔(dān)因您的行為而導(dǎo)致的法律責(zé)任,
本站有權(quán)保留或刪除有爭(zhēng)議評(píng)論。
參與本評(píng)論即表明您已經(jīng)閱讀并接受
上述條款。
V
特惠充值
聯(lián)系客服
APP下載
官方微信
返回頂部
分類選擇:
電腦辦公 平面設(shè)計(jì) 室內(nèi)設(shè)計(jì) 室外設(shè)計(jì) 機(jī)械設(shè)計(jì) 工業(yè)自動(dòng)化 影視動(dòng)畫 程序開發(fā) 網(wǎng)頁設(shè)計(jì) 會(huì)計(jì)課程 興趣成長(zhǎng) AIGC