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", "\t53656c65637420416c6c20556e75736564", "]", "/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", "\t44656c65746520537761746368", "]", "/value 3", "}", "}", "}"].join("\n");
var win = new Window("dialog", "(CJ)AI_色号生成器V2.2scD", undefined);
win.alignChildren = "fill";
win.spacing = 5;
var abIcon = "‰PNG\r\n\n\rIHDR+vtEXtSoftwareAdobe ImageReadyqÉe<gIDATxÚ”U]L›e~úÿµ”òñ_Ú¿)Ðp\tk€Hq!–É2.\\\"Ãzåî6¹Ü¼äÆ+â¼r‰Ù¸Ðx¡²‹M‰Ù$j¢‰Œ¨c„]”)?V~V´¥¿žó–2ºà˜'yó}mß÷yŸóœçœªðê¡x<
_f(^å€úe?†A½^?©ÕjŸÑòû|¾½½½è=ÓéüôÛ¸$I\nþOȲÜf±XÒJ×××§»:;ÓCCCélð{{{{º¼¬,Í{\n\n\nÆåq4/~QQQ1¢Ñh¾-))±EÁk§NattEEEbÝnG @
ͳٌ½½=·ZöÒE?íììüu,x]]ß´Zhnn†ÛíÆÀÀº»»ÑØØˆðßqè6p¸TWW3D£QqA8¶RR^\"5±½½Íw¹\\\nO–––JÌÖëõ¢££ƒuGmmxþŒÃöˆÎÕK ½H¥Rhmmeæâž²J¥rollLä€WUU%Éí¨¬D__œN§8À¬üÉ4¡jžÄ“&»EH‹ÅÄåkkkb4QlvûSú</ÜÒÓӣƑҲ2¾6Ò2ŠEÅB\"‘Àt$ŽHXOÓ!A¨¼¼üpKG𣍏„uùЊY.//&“\t555 ÍÄât)Mü°Áb\"
ÍH\nX%æ‹$ÍÏ{¢°Ì<»—34·õ{½Š§ç˜ue–[[[b‘‡«/âÀJ2
\rf¾Ë¬¯¶3EõÉîg^“у$y´Üd’©Ò¢HÌB¤¤V‹‹f£qüžREiøœƒŸsa8›˜œœÌ±3‘¥œaN7µ1GV’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ôÄ!Ç{{Ÿ\n:?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é*ŸÜ¸¿ß2jÅ4”¸`<SøYIz³ŸÉ¾·iù(“àQÕËôœ¾„üzþÏ••ÁÇd3ö²™êa£?\tšžA*ümê‰7Μ9öû_¤wæ¢\nrÂxIEND®B`‚";
var pan1 = win.add("panel", undefined, "选色");
pan1.alignChildren = "top";
pan1.orientation = "row";
var pan11 = pan1.add("panel", undefined, "CMYK四原色(中英文)");
pan11.alignChildren = "left";
pan11.spacing = 3;
var gi11 = pan11.add("group");
gi11.orientation = "row";
gi11.alignChildren = "left";
var rb113 = gi11.add("radiobutton", undefined, "无");
var rb111 = gi11.add("radiobutton", undefined, "全部");
rb111.value = true;
var rb112 = gi11.add("radiobutton", undefined, "自定");
var gi12 = pan11.add("group");
var cb121 = gi12.add("checkbox", undefined, "C");
var cb122 = gi12.add("checkbox", undefined, "M");
var cb123 = gi12.add("checkbox", undefined, "Y");
var cb124 = gi12.add("checkbox", undefined, "K");
var spacePan11 = pan11.add("panel", [0, 0, undefined, 2], "");
spacePan11.alignment = "fill";
var gi13 = pan11.add("group");
var cb131 = gi13.add("checkbox", undefined, "只列英文");
var cb132 = gi13.add("checkbox", undefined, "只列中文");
cb121.enabled = cb122.enabled = cb123.enabled = cb124.enabled = false;
cb121.value = cb122.value = cb123.value = cb124.value = true;
rb111.onClick = function () {
rb111.value == true;
cb121.value = cb122.value = cb123.value = cb124.value = cb131.enabled = cb132.enabled = true;
cb121.enabled = cb122.enabled = cb123.enabled = cb124.enabled = false;
};
rb112.onClick = function () {
rb112.value == true;
cb121.value = cb122.value = cb123.value = false;
cb124.value = true;
cb121.enabled = cb122.enabled = cb123.enabled = cb124.enabled = cb131.enabled = cb132.enabled = true;
};
rb113.onClick = function () {
rb111.value == true;
cb121.value = cb122.value = cb123.value = cb124.value = cb131.value = cb132.value = false;
cb121.enabled = cb122.enabled = cb123.enabled = cb124.enabled = cb131.enabled = cb132.enabled = false;
};
var pan12 = pan1.add("panel", undefined, "特别色");
pan12.spacing = 4.5;
var gi12 = pan12.add("group");
gi12.orientation = "row";
gi12.alignment = "left";
var rb121 = gi12.add("radiobutton", undefined, "无");
var rb122 = gi12.add("radiobutton", undefined, "全部");
rb122.value = true;
var cb1221 = pan12.add("checkbox", undefined, "简化PANTONE名称");
var spacePan12 = pan12.add("panel", [0, 0, undefined, 2], "");
spacePan12.alignment = "fill";
var st1221 = pan12.add("statictext", undefined, "(例:871 C 186 C ...)");
st1221.alignment = "right";
var pan2 = win.add("panel", undefined, "相关选项");
pan2.alignChildren = "fill";
var pan21 = pan2.add("panel", undefined, "排列方式");
var gi21 = pan21.add("group");
gi21.orientation = "row";
gi21.alignment = "left";
var rb211 = gi21.add("radiobutton", undefined, "一排");
rb211.value = true;
var rb212 = gi21.add("radiobutton", undefined, "两排");
var pan22 = pan2.add("panel", undefined, "位置");
var gi22 = pan22.add("group");
gi22.orientation = "row";
gi22.alignment = "left";
var rb221 = gi22.add("radiobutton", undefined, "置于屏幕正中");
rb221.value = true;
var rb222 = gi22.add("radiobutton", undefined, "置于页面左上角外");
var rb223 = gi22.add("radiobutton", undefined, "手动黏贴");
var pan23 = pan2.add("panel", undefined, "其他");
var gi23 = pan23.add("group");
gi23.orientation = "row";
gi23.alignment = "left";
var cb231 = gi23.add("checkbox", undefined, "选取状态");
cb231.value = true;
var cb232 = gi23.add("checkbox", undefined, "两者再编组");
cb232.value = true;
var cb233 = gi23.add("checkbox", undefined, "色号后附加油墨总数");
cb233.value = true;
var giEnd = win.add("group");
giEnd.alignment = "center";
var okBtn = giEnd.add("button", undefined, "运行", {
name: "ok"
});
var cancelBtn = giEnd.add("button", undefined, "取消", {
name: "cancel"
});
var spacePan2 = win.add("panel", [0, 0, undefined, 2], "");
var giSign = win.add("group");
giSign.spacing = 0;
giSign.alignment = "center";
var cpcImg = "‰PNG\r\n\n\rIHDR(d×=tEXtSoftwareAdobe ImageReadyqÉe<ÄIDATxÚÌVËOaˆÚÖˆÙ\nÑmÏCY¸\\l‹yĤÜ[IƘÒxE‘@à`D!h4áe¤âÁ.^@\"¡
ƒ8l°õa#ZÅ™åÛ¥-†“|Ùô{Ío~ó›ù\npÂ-+uâ^Û]?GÇ«§}ÏSö¶ã‡;â~:;ˆçä”s6æƒg~‚\t>f2ă.ütW¯TsE‘b¸°“DãÆ:˜ý\"œÞÚ\nãº/\t’Îl+++3¢
Bð+%pvv†‚7¶Êª*(++SöíÆbð÷†¾‡X,Öƒ{½i\tœ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’×\nVÝç––º.>é&ý)kL&Ø”½WÓ0›Y‚ÒòrÐ[ãqM5\nš$ɉƒã££ÚÓ¦@š=ÅæxSül{hnÔÁ“À¥Ë]:šdT0©ECÌD£QÈÏÏ׿H¨³0Þïd÷Ï`AI::Ò:Bö!m˜±ý¬ƒQ„”öÁKa\t¾-,(ãg$ÿi/8,úÊz’cUÞőԡúUîîu¶¡i^ô]ïÆ(—||/nû,ŠÇ•õ:»CP € êP5é `¨¯õnËò¸æSRàp]D“8u‹ŠIF‘.‰là¤è·\nÖŠƒ\n¤¯Ç;É}š.mû.KËË8ƒÁ€—óÊ™ÔB‘··\tѯö1™úK£Œ©åTÞli!\r\n8'f¥A‰£¯ìY[-ðÌÏ•pWjV”‰¢âˆ’Êûžd–êìv0œ1̰ίÛmR_f½>Ÿ¯“µek4\rµ©ìÒ4Èž\"÷ð©µêz%æ(µÞBÀœÇ}SÑÇct>AÕKýRϨxh½&3zO¥l 7w‡'&××ãó““£¤•1GOÌš{@§X¼¸Þ“\t(ž£&ßNO5fj?$\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;
}
}
}
}
合理的脚本代码可以有效的提高工作效率,减少重复劳动。
文章引用至 作者知了-联系方式1
文章引用至 作者知了-联系方式2