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;
}
承擔因您的行為而導致的法律責任,
本站有權保留或刪除有爭議評論。
參與本評論即表明您已經(jīng)閱讀并接受
上述條款。