illustrator插件色标生成器AI插件
1 方法原理
illustrator是矢量编辑软件,画板是绘制处理的重要容器,在印刷方面的一个重要功能就是色标生成器,开发一个 色标生成器功能 ,以下功能仅用于学习交流,请勿用于非法用途和商业用途,源代码如下所示: var doc = app.activeDocument; app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM; doc.rulerOrigin = [0, doc.height]; var lay = doc.activeLayer; var ab = doc.artboards; var arrSpotColor = new Array(); doc.selection = null; var doc = app.activeDocument; var swaSpot = doc.spots; for (var i = 0; i < swaSpot.length; i += 1) { if (swaSpot[i].colorType == "ColorModel.REGISTRATION") { regName = swaSpot[i].name; break; } } var col1 = new CMYKColor(); col1.black = 0; col1.magenta = 0; col1.cyan = 100; col1.yellow = 0; var col2 = new CMYKColor(); col2.black = 0; col2.magenta = 100; col2.cyan = 0; col2.yellow = 0; var col3 = new CMYKColor(); col3.black = 0; col3.magenta = 0; col3.cyan = 0; col3.yellow = 100; var col4 = new CMYKColor(); col4.black = 100; col4.magenta = 0; col4.cyan = 0; col4.yellow = 0; var colAll = new Array(); colAll[0] = col1; colAll[1] = col2; colAll[2] = col3; colAll[3] = col4; var set = "Set_ClearUnuseSwatches"; var action1 = "Action_ClearUnuseSwatches"; var actionStr1 = ["/version 3", "/name [ 22", "5365745f436c656172556e7573655377617463686573", "]", "/isOpen 1", "/actionCount 1", "/action-1 {", "/name [ 25", "416374696f6e5f436c656172556e7573655377617463686573", "]", "/keyIndex 0", "/colorIndex 0", "/isOpen 1", "/eventCount 2", "/event-1 {", "/useRulersIn1stQuadrant 0", "/internalName (ai_plugin_swatches)", "/localizedName [ 8", "5377617463686573", "]", "/isOpen 0", "/isOn 1", "/hasDialog 0", "/parameterCount 1", "/parameter-1 {", "/key 1835363957", "/showInPalette -1", "/type (enumerated)", "/name [ 17", " 53656c65637420416c6c20556e75736564", "]", "/value 11", "}", "}", "/event-2 {", "/useRulersIn1stQuadrant 0", "/internalName (ai_plugin_swatches)", "/localizedName [ 8", "5377617463686573", "]", "/isOpen 0", "/isOn 1", "/hasDialog 1", "/showDialog 0", "/parameterCount 1", "/parameter-1 {", "/key 1835363957", "/showInPalette -1", "/type (enumerated)", "/name [ 13", " 44656c65746520537761746368", "]", "/value 3", "}", "}", "}"].join(" "); var win = new Window("dialog", "(CJ)AI_色号生成器V2.2scD", undefined); win.alignChildren = "fill"; win.spacing = 5; var abIcon = "‰PNGr rIHDR +v tEXtSoftwareAdobe ImageReadyqÉe< gIDATxÚ"U]L›e ~úÿµ"òñ_Ú ¿)Ð p k Hq!–É2."Ãzåî6¹Ü¼äÆ+â¼r‰Ù Ðx¡²‹M‰Ù $j ‰Œ c„]")?V~V ¿žó–2ºà "yó}mß yŸóœçœªðê¡x< _f(^å úe? †A½^? ÕjŸÑòû|¾ ½½½ è= ÓéüôÛ $I þOȲÜf X ÒJ §»:;ÓCCCélð{{{{º¼ ,Í{ Æå q4/~QQQ1 Ñh¾-)) EÁk§Natt EEEb ÝnG @ Í ³ÙŒ½½=·Z öÒE?íììüu,x]] ß Z hnn†ÛíÆÀÀº»»ÑØ؈ðßqè6 p TWW3 D QqA8 ¶RR^"5 ½½ Í w¹ O–––JÌÖëõ ƒuGmm xþ ŒÃöˆÎÕK ½H Rhmmeæâ ž²J rollLä WUU %Éí D__ œN§8À üÉ4 ¡ jžÄ" &»EH ‹ÅÄåkkkb 4 QlvûSúÜÒÓÓ Æ‘Ò²2¾ 6Ò2 ŠEÅB"‘Àt$Ž H XOÓ!A ¼¼üp KGš „uùЊ Y.// &" 555 ÍÄât)Mü Áb" ÍH X%æ‹$ÍÏ{ Ì<»—34 ·õ{½Š§ ç ue–[[[b‘‡ «/âÀJ2 rf¾ Ë ¶3 EõÉîg ^ "Ñ ƒ$y Üd’ Ò HÌB V‹‹f qüžR EiøœƒŸsa8› œœÌ 3‘ œaN7µ1 GV’H$‚õõu|i" J ym2óÕøóõy&»†††Ãs -Øæ’Ñ8ŸJ§Ûس ! ù !‹Œ ó ñ C ÅžSü8|`CSS ŽŽrÐxÈ "VA– ÙNÉd »»»pvªqU áá¡_~"pÝ Î‘àôT §ßy]H üü|6²ö@–YºÉÃEáØßßG( »ÎïáÒo ~dÅõ ) ¼oú Î ½ dbç%S õA ·Ø |# ³K$CôÄ!Ç{ {Ÿ :?66¶,À ^»¶LÝ9SG ÆA T ÿ ª9 œ½ rö ƒ¼Oà åÌsJÇGC"ØÒÒ"2`ðO?3Ÿ ~và-Ñ@KKK<ŸØ 3— ¹• þÞ KËdü yNð å po6 ïZþ xàÜ9Ô"rÙ)]]] ¡ n ;r æ/ r= ? A sssøæž ÏB2š öñÝ „Õu-ò >o_ 7Ïö#I.á~("åejÂþ‹ÃËY<ÕqŒî޹㡠ºIé*ŸÜ ¿ß 2 jÅ4" `f2 ă.ütW TsE‘b " DãÆ: ý"œÞÚ ãº / ’ Îl +++3 Bð+ %pvv†‚ 7 ¶Êª*(++SöíÆb𠆾 ‡X,Öƒ{½i œiÏ4pgºrŠ"Eš"kû‡ ó ïÃ"â ³X, »µõÈ ÍÍÎÂGŸ HD &Ô74‚L§[–áõÈ E »i.;! ž Þ$p ¶ÙØ Û Ð ›Ot – ¹šÚZ@ é~ œÍͺàÈ8ŽƒÛ 0 »X6 ubZ¡p³PÛ<_ò zoô@aßsLñÆ!È Føk2Ù >", /ûûár² hfN‘ `w8 9L%Œ Áî ý~å7 G" F5 6k B;,Zý0l ’ VÝç––º.>é&ý)k L&Ø "½WÓ 0› Y‚ÒòrÐ[ãqM5 š $ɉƒã Ú Ó @š=ÅæxSül {hnÔÁ "À Ë ]: šdT0 ECÌD QÈÏÏ æH ³0Þïd Ï`AI ::Ò:Bö!m ý ƒQ „"öÁKa ¾-,(ãg$ ÿi/ 8, úÊz’cU ÞÅ‘ Ô¡úU îî u¶¡i ^ô]ïÆ(—||/nû,Š Ç•õ:»C P êP5é ` õnËò æ S Ràp]D "8u‹ŠI F ‘.‰l à è· ÖŠƒ Ç;É}š.m û. KËË 8ƒÁ —óÊ ÔB‘·· Ñ ö1 ú K Œ åT Þli!r 8" f A ‰ ìY[-ðÌÏ•pWjV"‰ −Êûžd–êìv0œ1Ì Î ÛmR_ f½>Ÿ "µ e k4 rµ ìÒ4Èž" ð µêz%æ(µ ÞBÀœÇ}SÑÇct>AÕKýRÏ xh ½&3zO l 7w‡"& ã ó "" •1GO Ìš{@§X¼ Þ" (ž &ßNO 5fj?$r ‡ò ä]‰ç³2âb}ŽW‹ˆ4—!uÇ6 œ+¡— /z ,N¼ý ` Ž²Ö ñºÈIEND B`‚"; var imgSign = giSign.add("image", undefined, cpcImg); var stSign = giSign.add("statictext", undefined, "CPC中印 "); var stSign2 = giSign.add("statictext", undefined, " by calvin530126"); okBtn.onClick = function () { txt4C = txtSpot = ""; if (rb113.value == true && rb121.value == true) { alert("请勿两种色号同时勾选"无""); rb111.value = rb122.value = true; return false; } else { if (rb111.value == true || rb112.value == true || rb122.value == true) { actAbIndex = ab.getActiveArtboardIndex(); var abSize = ab[actAbIndex].artboardRect; if (rb111.value == true || rb112.value == true) { for4cInfo(); var all4ColorSum = 4; var txt4cLen = Number(txt4C.contents.length); if (cb121.value == false) { all4ColorSum = all4ColorSum - 1; if (txt4cLen == 20) { var result = txt4C.contents.lastIndexOf("蓝色(C)"); for (i = result; i < (result + 5); i++) { txt4C.textRange.characters[result].remove(); } } if (txt4cLen == 8) { var result = txt4C.contents.lastIndexOf("蓝色"); for (i = result; i < (result + 2); i++) { txt4C.textRange.characters[result].remove(); } } if (txt4cLen == 4) { var result = txt4C.contents.lastIndexOf("C"); for (i = result; i < (result + 1); i++) { txt4C.textRange.characters[result].remove(); } } } if (cb122.value == false) { all4ColorSum = all4ColorSum - 1; if (txt4cLen == 20) { var result = txt4C.contents.lastIndexOf("洋红(M)"); for (i = result; i < (result + 5); i++) { txt4C.textRange.characters[result].remove(); } } if (txt4cLen == 8) { var result = txt4C.contents.lastIndexOf("洋红"); for (i = result; i < (result + 2); i++) { txt4C.textRange.characters[result].remove(); } } if (txt4cLen == 4) { var result = txt4C.contents.lastIndexOf("M"); for (i = result; i < (result + 1); i++) { txt4C.textRange.characters[result].remove(); } } } if (cb123.value == false) { all4ColorSum = all4ColorSum - 1; if (txt4cLen == 20) { var result = txt4C.contents.lastIndexOf("黄色(Y)"); for (i = result; i < (result + 5); i++) { txt4C.textRange.characters[result].remove(); } } if (txt4cLen == 8) { var result = txt4C.contents.lastIndexOf("黄色"); for (i = result; i < (result + 2); i++) { txt4C.textRange.characters[result].remove(); } } if (txt4cLen == 4) { var result = txt4C.contents.lastIndexOf("Y"); for (i = result; i < (result + 1); i++) { txt4C.textRange.characters[result].remove(); } } } if (cb124.value == false) { all4ColorSum = all4ColorSum - 1; if (txt4cLen == 20) { var result = txt4C.contents.lastIndexOf("黑色(K)"); for (i = result; i < (result + 5); i++) { txt4C.textRange.characters[result].remove(); } } if (txt4cLen == 8) { var result = txt4C.contents.lastIndexOf("黑色"); for (i = result; i < (result + 2); i++) { txt4C.textRange.characters[result].remove(); } } if (txt4cLen == 4) { var result = txt4C.contents.lastIndexOf("K"); for (i = result; i < (result + 1); i++) { txt4C.textRange.characters[result].remove(); } } } } if (rb122.value == true) { createAction(actionStr1, set); app.loadAction(f); f.remove(); app.doScript(action1, set); app.unloadAction(set, ""); forSpotColorInfo(); if (txtSpot == "") { alert("此档案没有使用特别色"); } } if (rb113.value == true) { all4ColorSum = 0; } if (rb121.value == true) { arrSpotColor.length = 0; } var allColorSum = Number(arrSpotColor.length) + Number(all4ColorSum); if (allColorSum != 0 && cb233.value == true) { txtForAllColorSum = doc.textFrames.add(); txtForAllColorSum.stroked = false; txtForAllColorSum.filled = true; txtForAllColorSum.textRange.fillColor = doc.swatches[regName].color; txtForAllColorSum.textRange.size = 10; txtForAllColorSum.textRange.characterAttributes.textFont = app.textFonts.MicrosoftYaHei; txtForAllColorSum.contents = "(共" + allColorSum + "色)"; } if (rb122.value == true && txtSpot != "") { if (rb211.value == true) { txt4C.top = abSize[0] + txt4C.height; } if (rb212.value == true) { txt4C.top = abSize[0] + txt4C.height + txtSpot.height; txt4C.left = abSize[1]; } } else { if (rb122.value == false) { txt4C.top = abSize[0] + txt4C.height; txt4C.left = abSize[1]; } } if (txtSpot != null) { if (rb211.value == true) { if (txt4C == "") { txtSpot.top = abSize[0] + txtSpot.height; txtSpot.left = abSize[1]; } else { if (txt4C != "") { txtSpot.top = abSize[0] + txtSpot.height; txtSpot.left = txt4C.width + abSize[1] + 2; } } } if (rb212.value == true) { txtSpot.top = abSize[0] + txtSpot.height; txtSpot.left = abSize[1]; } } if (cb233.value == true) { if (rb211.value == true) { txtForAllColorSum.top = abSize[0] + txtForAllColorSum.height; if (rb113.value != true && rb121.value != true) { txtForAllColorSum.left = txt4C.width + txtSpot.width + abSize[1] + 2; } if (rb113.value == true && txtSpot != "") { txtForAllColorSum.left = txtSpot.width + abSize[1] + 2; } if (rb121.value == true && txt4C != "") { txtForAllColorSum.left = txt4C.width + abSize[1] + 2; } } else { if (rb212.value == true) { if (rb113.value != true && rb121.value != true) { txtForAllColorSum.top = abSize[0] + txtForAllColorSum.height; txtForAllColorSum.left = txtSpot.width + abSize[1] + 2; } if (rb113.value == true && txtSpot != "") { txtForAllColorSum.top = abSize[0] + txtForAllColorSum.height; txtForAllColorSum.left = txtSpot.width + abSize[1] + 2; } if (rb121.value == true && txt4C != "") { txtForAllColorSum.top = abSize[0] + txtForAllColorSum.height; txtForAllColorSum.left = txt4C.width + abSize[1] + 2; } } } } if (cb232.value == true) { giAllTxt = doc.activeLayer.groupItems.add(); if (rb211.value == true || rb212.value == true) { if (rb113.value != true && rb121.value != true) { txt4C.move(giAllTxt, ElementPlacement.INSIDE); txtSpot.move(giAllTxt, ElementPlacement.INSIDE); } if (rb113.value == true && txtSpot != "") { txtSpot.move(giAllTxt, ElementPlacement.INSIDE); } if (rb121.value == true && txt4C != "") { txt4C.move(giAllTxt, ElementPlacement.INSIDE); } } if (cb233.value == true) { txtForAllColorSum.move(giAllTxt, ElementPlacement.INSIDE); } } if (txt4C != null) { txt4C.selected = true; } if (txtSpot != null) { txtSpot.selected = true; } if (txtForAllColorSum != null) { txtForAllColorSum.selected = true; } if (rb221.value == true) { if (txt4C != null) { txt4C.selected = true; } if (txtSpot != null) { txtSpot.selected = true; } app.executeMenuCommand("cut"); app.executeMenuCommand("paste"); if (cb231.value == false) { doc.selection = null; } } if (rb223.value == true) { if (txt4C != "") { txt4C.selected = true; } if (txtSpot != "") { txtSpot.selected = true; } app.executeMenuCommand("cut"); } } } win.close(); }; win.center(); win.show(); function createAction(act, set) { f = new File("~/Desktop/" + set + ".aia"); f.open("w"); f.write(act); f.close(); f.hidden = true; } function for4cInfo() { txt4C = lay.textFrames.add(); txt4C.fillColor = true; txt4C.strokeColor = false; txt4C.textRange.size = 10; if (cb131.value == false && cb132.value == false) { txt4C.contents = "蓝色(C)洋红(M)黄色(Y)黑色(K)"; } else if (cb131.value == true && cb132.value == true) { txt4C.contents = "蓝色(C)洋红(M)黄色(Y)黑色(K)"; } else if (cb131.value == true && cb132.value == false) { txt4C.contents = "CMYK"; } else { if (cb131.value == false && cb132.value == true) { txt4C.contents = "蓝色洋红黄色黑色"; } } var cha = txt4C.textRange.characters.length; txt4C.textRange.characterAttributes.textFont = app.textFonts[textFonts.name = "MicrosoftYaHei"]; var j = 0; var cd = 0; for (var i = 0; i < cha; i += 1) { txt4C.textRange.characters[i].characterAttributes.fillColor = colAll[j]; cd++; if (cb131.value == false && cb132.value == false && (cd % 5) == 0) { j++; } else if (cb131.value == true && cb132.value == true && (cd % 5) == 0) { j++; } else if (cb131.value == true && cb132.value == false && (cd % 1) == 0) { j++; } else { if (cb131.value == false && cb132.value == true && (cd % 2) == 0) { j++; } } } } function forSpotColorInfo() { var col = doc.swatches; var colLen = col.length; for (var i = 0; i < colLen; i += 1) { if (col[i].color.typename == "SpotColor" && col[i].color.spot.colorType == ColorModel.SPOT) { arrSpotColor.push(i) } } if (arrSpotColor.length != 0) { txtSpot = lay.textFrames.add(); txtSpot.textRange.size = 10; txtSpot.textRange.characterAttributes.textFont = app.textFonts[textFonts.name = "MicrosoftYaHei"]; for (var j = 0; j < arrSpotColor.length; j += 1) { var num = eval(arrSpotColor[j]); if (col[num].name.search(/PANTONE/i) != -1 && cb1221.value == true) { spotnameTem = col[num].name.slice(7, col[num].name.length); } else { spotnameTem = col[num].name; } txtSpot.textRange.characters.add(spotnameTem); var txtLength = txtSpot.contents.length; for (i = txtLength - spotnameTem.length; i < txtLength; i++) { txtSpot.textRange.characters[i].characterAttributes.fillColor = col[num].color; } } } }2.使用方式
AI源代码转执行脚本
>文章引用至 作者联系方式