illustrator插件--脚本插件集合--查找专色--两者换位--导出PSD--导出jpg--随机填色--选择增强

    科技2022-07-11  106

      illustrator是矢量编辑软件,如需查找专色,两者换位,选择导出-PSD,导出jpg,选择导出jpg,选择增强和随机填色时,脚本插件可以有效的提高效率,如查找专色和选择导出-psd源代码如下所示:

    //查找专色 if (activeDocument.documentColorSpace == "DocumentColorSpace.RGB") { var space = "RGB"; } else { var space = "CMYK"; } var PMSLibs = confirm("要包含粉彩类吗?"); var solidNames = [...]; var solidRGB = [...]; Arr1 = solidNames; Arr2 = solidRGB; Arr3 = solidCMYK; if (PMSLibs == true) { var pastelU_Names = [...]; var pastelC_Names = [...]; push2(pastelC_Names, pastelU_Names); push2(Arr1, pastelC_Names); if (space == "RGB") { var pastelU_RGB = [ ... ]; var pastelC_RGB = [ ... ]; push2(pastelC_RGB, pastelU_RGB); push2(Arr2, pastelC_RGB); } else { var pastelC_CMYK = [ ... ]; var pastelU_CMYK = [ ... ]; push2(pastelC_CMYK, pastelU_CMYK); push2(Arr3, pastelC_CMYK); } } var names = Arr1; var maxprec = 21; if (space == "RGB") { cols = Arr2; } else { cols = Arr3; } if (activeDocument.selection.length > 0 && activeDocument.selection[0].fillColor != null) { if (activeDocument.selection[0].fillColor.typename == "CMYKColor") { fil = activeDocument.selection[0].fillColor; inpt = fil.cyan + "," + fil.magenta + "," + fil.yellow + "," + fil.black; } else if (activeDocument.selection[0].fillColor.typename == "RGBColor") { fil = activeDocument.selection[0].fillColor; inpt = fil.red + "," + fil.green + "," + fil.blue; } else { msg = "选择的颜色:" + activeDocument.selection[0].fillColor.typename + "不是RGB或者CMYK,有可能是渐变对象。"; inpt = getManual(msg); } if (inpt.length > 1) { getCols(); } } else { inpt = getManual(); getCols(); } function push2(arr1, arr2) { var alen = arr2.length; for (var x = 0; x < alen; x += 1) { arr1.push(arr2[x]); } } function getDefFill() { defObj = activeDocument.defaultFillColor; if (defObj.typename == "SpotColor") { defObj = activeDocument.defaultFillColor.spot.color; } if (defObj.typename == "RGBColor") { return defObj.red + "," + defObj.green + "," + defObj.blue; } else if (defObj.typename == "CMYKColor") { return defObj.cyan + "," + defObj.magenta + "," + defObj.yellow + "," + defObj.black; } else { alert(defObj.typename + " not understood"); return "0,0,0,0"; } } function getManual(msg) { if (msg == undefined) { msg = "No object was found, or color detection failed"; } return prompt(msg + ":\n点击确定使用当前的填色,或者\n输入以英文逗号隔开的" + space + "值(如61,10,45,5)", ""); } function getCols(prec) { if (prec == undefined) { prec = 1; } if (inpt == null || inpt.length == 0) { inpt = getDefFill(); } num = inpt.split(","); colen = cols.length; len = names.length; loc = 0; oneFound = false; matchlist = []; for (var j = 0; j < colen; j += 1) { isbest = compare(num, cols[j], cols[loc], prec); if (isbest == true) { oneFound = true; matchlist.push(names[j]); loc = j; } } if (oneFound == true) { if (space == "CMYK") { myCol = "C:" + Math.round(num[0]) + "," + "M:" + Math.round(num[1]) + "," + "Y:" + Math.round(num[2]) + "," + "K:" + Math.round(num[3]); } else { myCol = "R:" + Math.round(num[0]) + "," + "G:" + Math.round(num[1]) + "," + "B:" + Math.round(num[2]); } alert(myCol + "\n较匹配\n" + matchlist.join("\n") + "\n→仅供" + prec + "参考←"); } else { if (prec > maxprec) { newmax = prompt("没有找到相匹配的" + maxprec + " deg.\n按回车退出,或者重新输入数值再查找一次。", ""); if (newmax.length > 0) { maxprec = newmax; prec++; getCols(prec); } } else { prec++; getCols(prec); } } } function compare(arr1, arr2, arrBest, precs) { var d1 = 0; max = arr1.length; for (var w = 0; w < max; w += 1) { d1 = diff(arr1[w], arr2[w]); if (d1 > precs) { return false; } } return true; } function diff(a, b) { if (a > b) { return a - b; } else { return b - a; } } //导出PSD var doc = app.activeDocument; var obj = doc.selection; var mLayer = doc.activeLayer; var destFolder = null; var docSelected = doc.selection; var mem = new Array(); var cropOLD = new Array(); var errorIcon = true; var strSaveDialog = "另存为"; var prefStr = "设定导出参数:分辨率、颜色模式 (CMYK, Grayscale, RGB)注意大小写 、是否嵌入颜色配置文件 (1 - 是, 0 - 否);"; var pref = "150;CMYK;1"; var opt = new ExportOptionsPhotoshop(); var type = ExportType.PHOTOSHOP; opt.antiAliasing = true; opt.resolution = 150; opt.editableText = false; opt.maximumEditability = false; opt.warnings = false; opt.writeLayers = false; var start = false; var next = false; var bnd = new Array(); if (documents.length > 0) { if (str = prompt(prefStr, pref, "导出选定对象为PSD")) { param = str.split(";"); opt.resolution = param[0]; if (((param[1] == "CMYK") | (param[1] == "Grayscale")) | (param[1] == "RGB")) { switch (param[1]) { case "CMYK": opt.imageColorSpace = ImageColorSpace.CMYK; break; case "Grayscale": opt.imageColorSpace = ImageColorSpace.Grayscale; break; case "RGB": opt.imageColorSpace = ImageColorSpace.RGB; break; } next = true; } else { next = errorMes(1); } if ((param[2] == 0) | (param[2] == 1)) { switch (param[2]) { case 0: opt.embedICCProfile = false; break; case 1: opt.embedICCProfile = true; break; } next = true; } else { next = errorMes(2); } } else { next = false } if (next) { if (obj.length > 0) { bnd = getBounds(obj); W = bnd[2] - bnd[0]; H = bnd[1] - bnd[3]; X = bnd[0]; Y = bnd[1]; start = true; } else { doc.rulerOrigin = Array(0, 0); bnd[0] = 0; bnd[2] = doc.width; bnd[1] = doc.height; bnd[3] = 0; } cropOLD = doc.cropBox; doc.cropBox = bnd; doc.cropStyle = CropOptions.Standard; if (start) { var j = 0; for (var i = 0; i < doc.layers.length; i += 1) { if (doc.layers[i].visible) { doc.layers[i].visible = false; } else { mem[j] = i; j = j + 1; } } var mLayer = doc.layers.add(); mLayer.zOrder(ZOrderMethod.SENDTOBACK); for (var j = 0; j < docSelected.length; j += 1) { newItem = docSelected[j].duplicate(doc, ElementPlacement.PLACEATEND) } } str = ""; var destFolder = File.saveDialog(strSaveDialog, "Photoshop:*.psd"); if (destFolder != null) { str = destFolder + ""; fold = str.split("."); targetFile = ""; if (fold.length > 1) { for (var i = 0; i < fold.length - 1; i += 1) { targetFile = targetFile + fold[i]; } targetFile = targetFile + ".psd"; } else { targetFile = destFolder + ".psd"; } var saveName = new File(targetFile); doc.exportFile(saveName, type, opt); } doc.cropBox = cropOLD; if (start) { mLayer.remove(); j = 0; for (var i = 0; i < doc.layers.length; i += 1) { doc.layers[i].visible = true; } for (var i = 0; i < mem.length; i += 1) { j = mem[i]; doc.layers[j].visible = false; } } } } function errorMes(i) { var er = false; var errorStr = "无效的参数: " + param[i]; alert(errorStr, "AI-Show提示你", errorIcon); return er; } function getBounds(obj) { var selObj1 = new Array(); var selObj2 = new Array(); var vgb1 = new Array(); var vgb2 = new Array(); var n = obj.length; if (n > 0) { if (obj[0].typename == "GroupItem" && obj[0].clipped && obj[0].pageItems.length > 1) { clipObj = obj[0].pathItems[0].geometricBounds; vgb1 = clipObj; } else { selObj1 = obj[0]; vgb1 = selObj1.visibleBounds; } if (n > 1) { for (var i = 1; i < n; i += 1) { selObj2 = obj[i]; if (obj[i].typename == "GroupItem" && obj[i].clipped && obj[i].pageItems.length > 1) { vgb2 = obj[i].pathItems[0].geometricBounds; } else { vgb2 = selObj2.visibleBounds; } if (vgb1[0] > vgb2[0]) { vgb1[0] = vgb2[0] } if (vgb1[1] < vgb2[1]) { vgb1[1] = vgb2[1] } if (vgb1[2] < vgb2[2]) { vgb1[2] = vgb2[2] } if (vgb1[3] > vgb2[3]) { vgb1[3] = vgb2[3] } } } } return vgb1; }

      界面如下图所示:   合理的脚本代码可以有效的提高工作效率,减少重复劳动。


      欢迎光临知了软件开发网络平台,本公司定制开发各类软件,主要方向为桌面专业软件开发和插件定制开发,桌面软件主要包括文字图形识别类软件,信息管理类软件,3D打印类软件,视频类软件以及其它涉及专业的各类图形图像处理软件。插件包含AE插件,AI插件,PS插件,PDF插件,3DMAX插件以及Word,Excel等Office插件开发。详情请咨询,微信QQ:312117271,手机:18928899728,邮箱: anjingzhi_sea@163.com. 公司网址:http://www.zhiliaos.com

    Processed: 0.010, SQL: 8