论坛帮助 |
社区圈子 |
日历事件 |
2023-08-26, 15:20 | 只看该作者 #7 | ||
|
|||
正式会员
等级: 六袋长老
|
引用:
#targetengine main // DIALOG // ====== var dialog = new Window("palette", undefined, undefined, {maximizeButton: false, minimizeButton: false, closeButton: false}); dialog.text = "更改画板尺寸"; dialog.orientation = "column"; dialog.alignChildren = ["center","center"]; dialog.spacing = 5; dialog.margins = [10,10,10,5]; // PNLOPTIONS // ========== var pnlOptions = dialog.add("panel", undefined, undefined, {name: "pnlOptions"}); pnlOptions.text = "选项"; pnlOptions.orientation = "column"; pnlOptions.alignChildren = ["left","top"]; pnlOptions.spacing = 10; pnlOptions.margins = 10; // GRPWIDTH // ======== var grpWidth = pnlOptions.add("group", undefined, {name: "grpWidth"}); grpWidth.orientation = "row"; grpWidth.alignChildren = ["left","center"]; grpWidth.spacing = 10; grpWidth.margins = 0; var lblWidth = grpWidth.add("statictext", undefined, undefined, {name: "lblWidth"}); lblWidth.text = "宽度"; var txtWidth = grpWidth.add('edittext {properties: {name: "txtWidth"}}'); txtWidth.text = "210"; txtWidth.preferredSize.width = 50; txtWidth.onChange = function() { txtWidth.text = txtWidth.text.replace(/[^0-9.]/g, ""); }; var lblWidthUnit = grpWidth.add("statictext", undefined, undefined, {name: "lblWidthUnit"}); lblWidthUnit.text = "mm"; // GRPHEIGHT // ========= var grpHeight = pnlOptions.add("group", undefined, {name: "grpHeight"}); grpHeight.orientation = "row"; grpHeight.alignChildren = ["left","center"]; grpHeight.spacing = 10; grpHeight.margins = 0; var lblHeight = grpHeight.add("statictext", undefined, undefined, {name: "lblHeight"}); lblHeight.text = "高度"; var txtHeight = grpHeight.add('edittext {properties: {name: "txtHeight"}}'); txtHeight.text = "285"; txtHeight.preferredSize.width = 50; txtHeight.onChange = function() { txtHeight.text = txtHeight.text.replace(/[^0-9.]/g, ""); }; var lblHeightUnit = grpHeight.add("statictext", undefined, undefined, {name: "lblHeightUnit"}); lblHeightUnit.text = "mm"; // PNLOPTIONS // ========== var cbAllArtboard = pnlOptions.add("checkbox", undefined, undefined, {name: "cbAllArtboard"}); cbAllArtboard.helpTip = "选中:更改文档中所有画板尺寸\n不选中:只更改当前激活画板尺寸"; cbAllArtboard.text = "所有画板"; // GRPACTIONS // ========== var grpActions = dialog.add("group", undefined, {name: "grpActions"}); grpActions.orientation = "row"; grpActions.alignChildren = ["left","center"]; grpActions.spacing = 10; grpActions.margins = 0; var btnOk = grpActions.add("button", undefined, undefined, {name: "btnOk"}); btnOk.text = "确定"; btnOk.onClick = function() { do_Actions("main()"); dialog.close(); } var btnCancel = grpActions.add("button", undefined, undefined, {name: "btnCancel"}); btnCancel.text = "关闭"; btnCancel.onClick = function() { dialog.close(); } dialog.show(); function do_Actions(Message) { var b = new BridgeTalk(); b.target = "illustrator"; b.body = Message; b.send(); } function main() { try { var idoc = app.activeDocument; var width = new UnitValue(parseFloat(txtWidth.text), "mm").as( "pt"); var height = new UnitValue(parseFloat(txtHeight.text), "mm").as( "pt"); if(cbAllArtboard.value){ for (i=0; i<idoc.artboards.length; i++) { var abBounds = idoc.artboards[i].artboardRect; var aa = resizeArtboards(abBounds, width, height); idoc.artboards[i].artboardRect = [aa.left, aa.top, aa.right, aa.bottom]; } } else { var ab = idoc.artboards.getActiveArtboardIndex(); var abBounds = idoc.artboards[ab].artboardRect; var aa = resizeArtboards(abBounds, width, height); idoc.artboards[ab].artboardRect = [aa.left, aa.top, aa.right, aa.bottom]; } } catch(e) { alert(e.message); } } function resizeArtboards(abBounds, width, height) { var ableft = abBounds[0]; var abtop = abBounds[1]; var abwidth = abBounds[2] - ableft; var abheight = abtop- abBounds[3]; var abctrx = abwidth / 2 + ableft; var abctry = abtop - abheight / 2; var ableft = abctrx - width / 2; var abtop = abctry + height / 2; var abright = abctrx + width / 2; var abbottom = abctry - height / 2; var props = { left: ableft, top: abtop, right: abright, bottom: abbottom } return props; } // 设置确定按钮为默认元素,以便触发回车键点击事件 dialog.defaultElement = OKdialog; 大师能不能帮我改一下,要是能用回车确定,顺手多了 |
||