var win = new Window("dialog", "我要自學(xué)網(wǎng)案例: 畫板劃分")
var msgPnl = win.add("panel", undefined, "選項(xiàng)")
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")
myX.helpTip = "請?zhí)钊胝麛?shù)!"
myY.helpTip = "請?zhí)钊胝麛?shù)!"
msgPnl.add("StaticText", undefined, "務(wù)必輸入正整數(shù)!")
msgPnl.add("StaticText", undefined, "務(wù)必輸入正整數(shù)!")
msgPnl.add("StaticText", undefined, "務(wù)必輸入正整數(shù)!")
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.onChange = function () {
var theText = Number(myX.text)
if (!theText) {
this.text = 1
}
}
myY.onChange = function () {
var theText = Number(myY.text)
if (!theText) {
this.text = 1
}
}
BtnOK.onClick = function () {
main(myX.text, myY.text)
win.close()
}
BtnCancel.onClick = function () {
win.close()
}
win.center()
win.show()
function main(w, h) {
var doc = app.activeDocument
// 獲取當(dāng)前選中畫板的位置/寬高
var arts = doc.artboards
var chooseArt = arts[arts.getActiveArtboardIndex()]
var chooseArtLeft = chooseArt.artboardRect[0]
var chooseArtTop = chooseArt.artboardRect[1]
var chooseArtRight = chooseArt.artboardRect[2]
var chooseArtBottom = chooseArt.artboardRect[3]
// 計(jì)算拆分后的寬/高度
var width = (chooseArtRight - chooseArtLeft) / w
var height = (chooseArtTop - chooseArtBottom) / h
// 添加畫板
for (var i = 0; i < h; i++) {
for (var j = 0; j < w; j++) {
arts.add([
chooseArtLeft + (j * width),
chooseArtTop - (i * height),
chooseArtLeft + (j * width) + width,
chooseArtTop - (i * height) - height
]);
}
}
// 刪除原畫板
chooseArt.remove()
}
承擔(dān)因您的行為而導(dǎo)致的法律責(zé)任,
本站有權(quán)保留或刪除有爭議評論。
參與本評論即表明您已經(jīng)閱讀并接受
上述條款。