300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > illustrator插件-拼版功能开发-自动拼版-js脚本开发-ai插件

illustrator插件-拼版功能开发-自动拼版-js脚本开发-ai插件

时间:2023-10-07 08:52:41

相关推荐

illustrator插件-拼版功能开发-自动拼版-js脚本开发-ai插件

文章目录

1.算法程序2.作者答疑

1.算法程序

illustrator是矢量编辑软件,画板是绘制处理的重要容器,在印刷方面的一个重要功能就是拼版,开发一个自动拼版功能,源代码如下所示:

if (app.documents.length == 0) {Mydoc = app.documents.add();} else {Mydoc = app.activeDocument;}function MyfistDialog() {this.windowRef = null;}MyfistDialog.prototype.run = function() {var MyDocSelected = app.activeDocument.selection;if (MyDocSelected.length > 0) {var AutoX = Math.round((app.activeDocument.selection[0].width * 25.4) / 72, 2).toString();AutoY = Math.round((app.activeDocument.selection[0].height * 25.4) / 72, 2).toString();AutoXQty = Math.floor((Mydoc.width - 5) / app.activeDocument.selection[0].width).toString();AutoYQty = Math.floor((Mydoc.height - 5) / app.activeDocument.selection[0].height).toString();} else {AutoX = "0";AutoY = "0";AutoXQty = "1";AutoYQty = "1";}res = "dialog { \n\t\ttext: '自动拼版工具', \n\t\tmypnl: Panel { orientation:'column', alignChildren:['right', 'top'],\n\t\t\ttext: '拼版信息:', \n\t\t\tmyX: Group { orientation: 'row', \n\t\t\t\tst: StaticText { text:'成品水平尺寸' }, \n\t\t\t\tmyXSize: EditText { characters: 5,text:" + AutoX + ", justify:'right' } \n\t\t\t\tst: StaticText { text:'mm水平共拼' }, \n\t\t\t\tmyXQty : EditText { characters: 3,text:" + AutoXQty + ", justify:'right' } \n\t\t\t\tst: StaticText { text:'个' }, \n\t\t\t}, \n\t\t\tmyY: Group { orientation: 'row', \n\t\t\t\tst: StaticText { text:'成品垂直尺寸' }, \n\t\t\t\tmyYSize: EditText { characters: 5,text:" + AutoY + ", justify:'right' } \n\t\t\t\tst: StaticText { text:'mm垂直共拼' }, \n\t\t\t\tmyYQty : EditText { characters: 3,text:" + AutoYQty + ", justify:'right' } \n\t\t\t\tst: StaticText { text:'个' }, \n\t\t\t}, \n\t\t}, \n\t\tmypnl2: Panel { orientation:'column', alignChildren:['right', 'top'],\n\t\t\ttext: '割线信息:(mm)', \n\t\t\tmyOther: Group { orientation: 'row', \n\t\t\tst: StaticText { text:'割线离成品' }, \n\t\t\tmyCropSpace : EditText { characters: 3,text:2, justify:'right' } \n\t\t\tst: StaticText { text:'割线长' }, \n\t\t\tmyCropLength : EditText { characters: 3,text:3, justify:'right' } \n\t\t\tst: StaticText { text:'成品间隙' }, \n\t\t\tmyBlood : EditText { characters: 3,text:0, justify:'right' } \n\t\t\t}, \n\t\t}, \n\t\tCheckboxs: Group { orientation: 'row', \n\t\t\tCheckContent: Checkbox { \n\t\t\t\torientation:'row', text:'带内容拼版.', value:false \n\t\t\t}, \n\t\t\tCheckCutline: Checkbox { \n\t\t\t\torientation:'row', text:'自动加割线', value:true \n\t\t\t}, \n\t\t}, \n\t\tmypnl3: Group { orientation: 'row', \n\t\t\tst: StaticText { text:'注:水平与垂直尺寸需>0, 拼数需≥1,其它值需≥0' }, \n\t\t} \n\t\tbuttons: Group { orientation: 'row', \n\t\t\tcancelBtn: Button { text:'取消', properties:{name:'cancel'} } \n\t\t\tokBtn: Button { text:'确定', properties:{name:'ok'} }, \n\t\t} \n}";myDialog = new Window(res);this.windowRef = myDialog;myDialog.buttons.okBtn.onClick = function() {myXSizeV = (Number(myDialog.mypnl.myX.myXSize.text) * 72) / 25.4;myXQtyV = Math.round(Number(myDialog.mypnl.myX.myXQty.text));myYSizeV = (Number(myDialog.mypnl.myY.myYSize.text) * 72) / 25.4;myYQtyV = Math.round(Number(myDialog.mypnl.myY.myYQty.text));myCropSpaceV = (Number(myDialog.mypnl2.myOther.myCropSpace.text) * 72) / 25.4;myCropLengthV = (Number(myDialog.mypnl2.myOther.myCropLength.text) * 72) / 25.4;myBloodV = (Number(myDialog.mypnl2.myOther.myBlood.text) * 72) / 25.4;StartpositionX = 0;StartpositionY = 0;if (app.activeDocument.selection.length > 0) {StartpositionX = app.activeDocument.selection[0].position[0];StartpositionY = (app.activeDocument.selection[0].position[1] - ((myYSizeV + myBloodV) * myYQtyV)) + myBloodV;}var isInputOk = false;if (myXSizeV > 0 && myXQtyV >= 1 && myYSizeV > 0 && myYQtyV >= 1 && myCropSpaceV >= 0 && myCropLengthV >= 0 && myBloodV >= 0) {isInputOk = true;}if ((myXQtyV * myYQtyV) > 5000) {isInputOk = false;}if (isInputOk == true) {myDialog.close();if (myDialog.Checkboxs.CheckContent.value) {AutoCopy(myXSizeV, myXQtyV, myYSizeV, myYQtyV, myBloodV, StartpositionX, StartpositionY);}if (myDialog.Checkboxs.CheckCutline.value) {AddCutline(myXSizeV, myXQtyV, myYSizeV, myYQtyV, myCropSpaceV, myCropLengthV, myBloodV, StartpositionX, StartpositionY);}}};myDialog.buttons.cancelBtn.onClick = function() {myDialog.close();};myDialog.show();return true;};if (typeof MyfistDialog_unitTest == "undefined") {new MyfistDialog().run();}function AutoCopy(myXSizeV, myXQtyV, myYSizeV, myYQtyV, myBloodV, StartpositionX, StartpositionY) {var MyDocSelected = app.activeDocument.selection;if (MyDocSelected.length > 0) {for (var v = 1; v <= myYQtyV; v += 1) {for (var h = 1; h <= myXQtyV; h += 1) {if (MyDocSelected.length > 0) {for (var i = 0; i < MyDocSelected.length; i += 1) {MyDocSelected[i].selected = false;if (v > 1 || h > 1) {newItem = MyDocSelected[i].duplicate(app.activeDocument, ElementPlacement.PLACEATEND);newItem.translate((myXSizeV + myBloodV) * (h - 1), -(myYSizeV + myBloodV) * (v - 1));}}} else {MyDocSelected.selected = false;newItem = MyDocSelected.parent.duplicate(app.activeDocument, ElementPlacement.PLACEATEND);newItem.left += ((myXSizeV + myBloodV) * (h - 1));newItem.top += (-(myYSizeV + myBloodV) * (v - 1));}}}}}function AddCutline(myXSizeV, myXQtyV, myYSizeV, myYQtyV, myCropSpaceV, myCropLengthV, myBloodV, StartpositionX, StartpositionY) {var MyDocSelected = app.activeDocument.selection;if (MyDocSelected.length > 0) {for (var v = 1; v <= 2; v += 1) {for (var h = 1; h <= 2; h += 1) {if (MyDocSelected.length > 0) {for (var i = 0; i < MyDocSelected.length; i += 1) {MyDocSelected[i].selected = false;if (v > 1 || h > 1) {}}} else {MyDocSelected.selected = false;}}}}var cmykColor = new CMYKColor();cmykColor.cyan = 0;cmykColor.yellow = 0;cmykColor.magenta = 0;cmykColor.black = 100;var MyCutlineGroup = activeDocument.groupItems.add();if (myBloodV != 0) {for (var i = 0; i < myXQtyV + 1; i += 1) {if (i > 0) {var MyTestPathBottom1 = MyCutlineGroup.pathItems.add();MyTestPathBottom1.setEntirePath(new Array(new Array((StartpositionX + ((myXSizeV + myBloodV) * i)) - myBloodV, StartpositionY - myCropSpaceV), new Array((StartpositionX + ((myXSizeV + myBloodV) * i)) - myBloodV, (StartpositionY - myCropSpaceV) - myCropLengthV)));MyTestPathBottom1.strokeColor = cmykColor;MyTestPathBottom1.stroked = true;MyTestPathBottom1.filled = false;MyTestPathBottom1.strokeWidth = 0.425196850393701;MyTestPathBottom1.selected = true;var MyTestPathUp1 = MyCutlineGroup.pathItems.add();MyTestPathUp1 = MyTestPathBottom1.duplicate();MyTestPathUp1.top += (((myYSizeV + myBloodV) * myYQtyV) - myBloodV) + (myCropSpaceV * 2) + myCropLengthV;MyTestPathUp1.strokeColor = cmykColor;MyTestPathUp1.stroked = true;MyTestPathUp1.filled = false;MyTestPathUp1.strokeWidth = 0.425196850393701;MyTestPathUp1.selected = true;}if (i < myXQtyV) {var MyTestPathBottom2 = MyCutlineGroup.pathItems.add();MyTestPathBottom2.setEntirePath(new Array(new Array(StartpositionX + ((myXSizeV + myBloodV) * i), StartpositionY - myCropSpaceV), new Array(StartpositionX + ((myXSizeV + myBloodV) * i), (StartpositionY - myCropSpaceV) - myCropLengthV)));MyTestPathBottom2.strokeColor = cmykColor;MyTestPathBottom2.stroked = true;MyTestPathBottom2.filled = false;MyTestPathBottom2.strokeWidth = 0.425196850393701;MyTestPathBottom2.selected = true;var MyTestPathUp2 = MyCutlineGroup.pathItems.add();MyTestPathUp2 = MyTestPathBottom2.duplicate();MyTestPathUp2.top += (((myYSizeV + myBloodV) * myYQtyV) - myBloodV) + (myCropSpaceV * 2) + myCropLengthV;MyTestPathUp2.strokeColor = cmykColor;MyTestPathUp2.stroked = true;MyTestPathUp2.filled = false;MyTestPathUp2.strokeWidth = 0.425196850393701;MyTestPathUp2.selected = true;}}for (var i = 0; i < myYQtyV + 1; i += 1) {if (i > 0) {var MyTestPathLeft1 = MyCutlineGroup.pathItems.add();MyTestPathLeft1.setEntirePath(new Array(new Array(StartpositionX - myCropSpaceV, (StartpositionY + ((myYSizeV + myBloodV) * i)) - myBloodV), new Array((StartpositionX - myCropSpaceV) - myCropLengthV, (StartpositionY + ((myYSizeV + myBloodV) * i)) - myBloodV)));MyTestPathLeft1.strokeColor = cmykColor;MyTestPathLeft1.stroked = true;MyTestPathLeft1.filled = false;MyTestPathLeft1.strokeWidth = 0.425196850393701;MyTestPathLeft1.selected = true;var MyTestPathRight1 = MyCutlineGroup.pathItems.add();MyTestPathRight1 = MyTestPathLeft1.duplicate();MyTestPathRight1.left += (((myXSizeV + myBloodV) * myXQtyV) - myBloodV) + (myCropSpaceV * 2) + myCropLengthV;MyTestPathRight1.strokeColor = cmykColor;MyTestPathRight1.stroked = true;MyTestPathRight1.filled = false;MyTestPathRight1.strokeWidth = 0.425196850393701;MyTestPathRight1.selected = true;}if (i < myYQtyV) {var MyTestPathLeft2 = MyCutlineGroup.pathItems.add();MyTestPathLeft2.setEntirePath(new Array(new Array(StartpositionX - myCropSpaceV, StartpositionY + ((myYSizeV + myBloodV) * i)), new Array((StartpositionX - myCropSpaceV) - myCropLengthV, StartpositionY + ((myYSizeV + myBloodV) * i))));MyTestPathLeft2.strokeColor = cmykColor;MyTestPathLeft2.stroked = true;MyTestPathLeft2.filled = false;MyTestPathLeft2.strokeWidth = 0.425196850393701;MyTestPathLeft2.selected = true;var MyTestPathRight2 = MyCutlineGroup.pathItems.add();MyTestPathRight2 = MyTestPathLeft2.duplicate();MyTestPathRight2.left += (((myXSizeV + myBloodV) * myXQtyV) - myBloodV) + (myCropSpaceV * 2) + myCropLengthV;MyTestPathRight2.strokeColor = cmykColor;MyTestPathRight2.stroked = true;MyTestPathRight2.filled = false;MyTestPathRight2.strokeWidth = 0.425196850393701;MyTestPathRight2.selected = true;}}} else {for (var i = 0; i < myXQtyV + 1; i += 1) {var MyTestPathBottom1 = MyCutlineGroup.pathItems.add();MyTestPathBottom1.setEntirePath(new Array(new Array((StartpositionX + ((myXSizeV + myBloodV) * i)) - myBloodV, StartpositionY - myCropSpaceV), new Array((StartpositionX + ((myXSizeV + myBloodV) * i)) - myBloodV, (StartpositionY - myCropSpaceV) - myCropLengthV)));MyTestPathBottom1.strokeColor = cmykColor;MyTestPathBottom1.stroked = true;MyTestPathBottom1.filled = false;MyTestPathBottom1.strokeWidth = 0.425196850393701;MyTestPathBottom1.selected = true;var MyTestPathUp1 = MyCutlineGroup.pathItems.add();MyTestPathUp1 = MyTestPathBottom1.duplicate();MyTestPathUp1.top += (((myYSizeV + myBloodV) * myYQtyV) - myBloodV) + (myCropSpaceV * 2) + myCropLengthV;MyTestPathUp1.strokeColor = cmykColor;MyTestPathUp1.stroked = true;MyTestPathUp1.filled = false;MyTestPathUp1.strokeWidth = 0.425196850393701;MyTestPathUp1.selected = true;}for (var i = 0; i < myYQtyV + 1; i += 1) {var MyTestPathLeft1 = MyCutlineGroup.pathItems.add();MyTestPathLeft1.setEntirePath(new Array(new Array(StartpositionX - myCropSpaceV, (StartpositionY + ((myYSizeV + myBloodV) * i)) - myBloodV), new Array((StartpositionX - myCropSpaceV) - myCropLengthV, (StartpositionY + ((myYSizeV + myBloodV) * i)) - myBloodV)));MyTestPathLeft1.selected = true;var MyTestPathRight1 = MyCutlineGroup.pathItems.add();MyTestPathRight1 = MyTestPathLeft1.duplicate();MyTestPathRight1.left += (((myXSizeV + myBloodV) * myXQtyV) - myBloodV) + (myCropSpaceV * 2) + myCropLengthV;MyTestPathRight1.selected = true;}}}

2.作者答疑

如有疑问,请留言。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。