var win = new Window("dialog", "我要自學網案例: 畫板劃分")
var msgPnl = win.add("panel", undefined, "選項")
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í)钊胝麛担?
myY.helpTip = "請?zhí)钊胝麛担?
msgPnl.add("StaticText", undefined, "務必輸入正整數!")
msgPnl.add("StaticText", undefined, "務必輸入正整數!")
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.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
// 獲取當前選中畫板的位置/寬高
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]
// 計算拆分后的寬/高度
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()
}
承擔因您的行為而導致的法律責任,
本站有權保留或刪除有爭議評論。
參與本評論即表明您已經閱讀并接受
上述條款。