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

var win = new Window("dialog", "畫板劃分Pro");
win.location = [100, 100];
var msgPnl = win.add("panel", undefined, "選項");
msgPnl.add("StaticText", undefined, "請輸入正整數(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, "免責聲明:文件壞了不賠!");
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 = "請?zhí)钊胝麛?shù)!填別的后果自負!";
myY.helpTip = "請?zhí)钊胝麛?shù)!填別的后果自負!";
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ā)教程
我要自學網(wǎng)商城 ¥70 元
進入購買
文章評論
0 條評論 按熱度排序 按時間排序 /350
添加表情
遵守中華人民共和國的各項道德法規(guī),
承擔因您的行為而導致的法律責任,
本站有權保留或刪除有爭議評論。
參與本評論即表明您已經(jīng)閱讀并接受
上述條款。
V
特惠充值
聯(lián)系客服
APP下載
官方微信
返回頂部
分類選擇:
電腦辦公 平面設計 室內設計 室外設計 機械設計 工業(yè)自動化 影視動畫 程序開發(fā) 網(wǎng)頁設計 會計課程 興趣成長 AIGC