function createWindow() {
var win = new Window("dialog", "我要自學(xué)網(wǎng)案例: 畫(huà)板增減尺寸")
// -----選項(xiàng)面板
var optionsPanel = win.add("panel", undefined, "選項(xiàng)")
optionsPanel.margins = 20;
optionsPanel.orientation = "column"
var confGroup = optionsPanel.add("group")
confGroup.orientation = "column"
// ----上邊
var topSetGroup = confGroup.add("group")
var topLabel = topSetGroup.add("statictext", undefined, "上邊:")
var topInput = topSetGroup.add("edittext", [0, 0, 50, 30], "0")
var topBtnGroup = topSetGroup.add("group")
topBtnGroup.orientation = "column"
var topAdd = topBtnGroup.add("button", [0, 0, 20, 15], "+")
var topSub = topBtnGroup.add("button", [0, 0, 20, 15], "-")
var middleSetGroup = confGroup.add("group")
// ----左邊
var leftSetGroup = middleSetGroup.add("group")
var leftLabel = leftSetGroup.add("statictext", undefined, "左邊:")
var leftInput = leftSetGroup.add("edittext", [0, 0, 50, 30], "0")
var leftBtnGroup = leftSetGroup.add("group")
leftBtnGroup.orientation = "column"
var leftAdd = leftBtnGroup.add("button", [0, 0, 20, 15], "+")
var leftSub = leftBtnGroup.add("button", [0, 0, 20, 15], "-")
var spaceGroup = middleSetGroup.add("group")
spaceGroup.margins = 20
spaceGroup.orientation = "row"
var eqCheck = spaceGroup.add("checkbox", undefined, "四邊等值");
eqCheck.value = true;
// ----右邊
var rightSetGroup = middleSetGroup.add("group")
var rightLabel = rightSetGroup.add("statictext", undefined, "右邊:")
var rightInput = rightSetGroup.add("edittext", [0, 0, 50, 30], "0")
var rightBtnGroup = rightSetGroup.add("group")
rightBtnGroup.orientation = "column"
var rightAdd = rightBtnGroup.add("button", [0, 0, 20, 15], "+")
var rightSub = rightBtnGroup.add("button", [0, 0, 20, 15], "-")
// ----下邊
var bottomSetGroup = confGroup.add("group")
var bottomLabel = bottomSetGroup.add("statictext", undefined, "下邊:")
var bottomInput = bottomSetGroup.add("edittext", [0, 0, 50, 30], "0")
var bottomBtnGroup = bottomSetGroup.add("group")
bottomBtnGroup.orientation = "column"
var bottomAdd = bottomBtnGroup.add("button", [0, 0, 20, 15], "+")
var bottomSub = bottomBtnGroup.add("button", [0, 0, 20, 15], "-")
var UnitSetGroup = confGroup.add("group")
UnitSetGroup.orientation = "row"
UnitSetGroup.alignment = "right"
UnitSetGroup.add("statictext", undefined, "單位: ")
var unitSel = UnitSetGroup.add("dropdownlist", undefined, [
"pt",
"mm",
"in",
"cm",
"m",
])
unitSel.selection = [1]
// ----功能
var actionGroup = win.add("group")
actionGroup.orientation = "row"
actionGroup.margins = 20
var aboutBtn = actionGroup.add("button", [0, 0, 60, 30], "關(guān)于")
var runBtn = actionGroup.add("button", [0, 0, 60, 30], "執(zhí)行")
var closeBtn = actionGroup.add("button", [0, 0, 60, 30], "關(guān)閉")
// ---------為控件添加事件
topInput.onChange = function () {
if (Number(this.text) + "" == "NaN") {
this.text = "0"
}
if (eqCheck.value) {
leftInput.text = this.text
rightInput.text = this.text
bottomInput.text = this.text
}
}
leftInput.onChange = function () {
if (Number(this.text) + "" == "NaN") {
this.text = "0"
}
if (eqCheck.value) {
topInput.text = this.text
rightInput.text = this.text
bottomInput.text = this.text
}
}
rightInput.onChange = function () {
if (Number(this.text) + "" == "NaN") {
this.text = "0"
}
if (eqCheck.value) {
topInput.text = this.text
leftInput.text = this.text
bottomInput.text = this.text
}
}
bottomInput.onChange = function () {
if (Number(this.text) + "" == "NaN") {
this.text = "0"
}
if (eqCheck.value) {
topInput.text = this.text
leftInput.text = this.text
rightInput.text = this.text
}
}
topAdd.onClick = function () {
topInput.text = Number(topInput.text) + 1
topInput.notify("onChange");
}
topSub.onClick = function () {
topInput.text = Number(topInput.text) - 1
topInput.notify("onChange");
}
leftAdd.onClick = function () {
leftInput.text = Number(leftInput.text) + 1
leftInput.notify("onChange");
}
leftSub.onClick = function () {
leftInput.text = Number(leftInput.text) - 1
leftInput.notify("onChange");
}
rightAdd.onClick = function () {
rightInput.text = Number(rightInput.text) + 1
rightInput.notify("onChange");
}
rightSub.onClick = function () {
rightInput.text = Number(rightInput.text) - 1
rightInput.notify("onChange");
}
bottomAdd.onClick = function () {
bottomInput.text = Number(bottomInput.text) + 1
bottomInput.notify("onChange");
}
bottomSub.onClick = function () {
bottomInput.text = Number(bottomInput.text) - 1
bottomInput.notify("onChange");
}
runBtn.onClick = function () {
creation(topInput.text, bottomInput.text, leftInput.text, rightInput.text, unitSel.selection, win)
}
aboutBtn.onClick = function () {
callMe()
}
closeBtn.onClick = function () {
win.close()
}
// ---------為控件添加事件
win.center()
win.show()
}
function callMe() {
var fileName = "_aiscript_about.url";
var shortcut = new File("" + Folder.temp + "/" + fileName);
var url = "https://www.51zxw.net/"
shortcut.open("w");
shortcut.writeln("[InternetShortcut]");
shortcut.writeln("URL=" + url);
shortcut.writeln();
shortcut.close();
shortcut.execute();
return
}
function creation(tw, bw, lh, rh, unit, win) {
try {
var doc = app.activeDocument;
} catch (error) {
alert("請(qǐng)至少打開(kāi)一個(gè)文檔.")
return
}
var topMargin = UnitValue(Number(tw), unit).as("pt");
var bottomMargin = UnitValue(Number(bw), unit).as("pt");
var leftMargin = UnitValue(Number(lh), unit).as("pt");
var rightMargin = UnitValue(Number(rh), unit).as("pt");
if (topMargin > 16382.8346 || bottomMargin > 16382.8346 || leftMargin > 16382.8346 || rightMargin > 16382.8346) {
alert("畫(huà)板尺寸已經(jīng)超出ai規(guī)定的范圍!")
return
}
var artboard = doc.artboards[doc.artboards.getActiveArtboardIndex()];
var oldBounds = artboard.artboardRect;
artboard.artboardRect = [
oldBounds[0] - leftMargin,
oldBounds[1] + topMargin,
oldBounds[2] + rightMargin,
oldBounds[3] - bottomMargin
];
win.close()
}
createWindow()
承擔(dān)因您的行為而導(dǎo)致的法律責(zé)任,
本站有權(quán)保留或刪除有爭(zhēng)議評(píng)論。
參與本評(píng)論即表明您已經(jīng)閱讀并接受
上述條款。