illustrator图案制作教程(illustrator插件画板功能开发-多图层转多画板-js开发-ai插件)

1.算法程序

illustrator是矢量编辑软件,画板是绘制处理的重要容器,开发一个多图层转多画板功能,源代码如下所示:

var doc = activeDocument; doc.rulerOrigin = [0, 0]; var layerN = doc.layers.length; for (var i = 1; i < layerN; i = 1) { doc.artboards.add([(i * doc.width) - 10000, doc.height, (doc.width * (i 1)) - 10000, 0]); } doc.rearrangeArtboards(DocumentArtboardLayout.GridByRow, Math.ceil(Math.sqrt(layerN)), 20, FALSE); var abArr = []; doEx("artboards").each(Function() { abArr.push([this.artboardRect[0], this.artboardRect[3]]); }); var i = 0; doEx("layers").each(function() { this.locked = false; this.visible = true; this.hasSelectedArtwork = true; doEx("selection").each(function() { this.top = abArr[i][1]; this.left = abArr[i][0]; }); doc.selection = null; i ; }); Function.prototype.curry = function() { var slice = Array.prototype.slice; var args = slice.apply(arguments); var that = this; return function() { return that.apply(this, args.concat(slice.apply(arguments))); }; }; function() { doEx = function() { return new doEx.prototype.init(Array.prototype.slice.apply(arguments)); }; doEx.selection = doEx.curry("selection"); doEx.prototype = { init: function() { if (!this.length) { this.length = 0 } var arg = Array.prototype.slice.apply(arguments)[0]; this.log.push("doEX_init : " arg.toString()); for (var i = 0; i < arg.length; i = 1) { var s = arg[i]; try { switch (s.constructor.name) { case "Object": try { for (var x in s) { this[x](s[x]); } } catch (e) { this.error.push("init_Object_error : " e); } break; case "Function": return doEx(s()); case "String": try { if (typeof this.objectShortName[s] == "string") { s = this.objectShortName[s] } s = app.activeDocument[s]; this.add(s); } catch (e) { this.error.push("objectShortName_error : " e); } break; case "Array": this.add(s); break; default: this.add(s); } } catch (e) { this.add(s); } } return this; }, add: function(s) { this.log.push("doEX_add : " s.toString()); var len = this.length; try { if (typeof s === "string") { s = doEx(s) } if (s.length) { s = Array.prototype.slice.call(s, 0); for (var i = 0; i < s.length; i = 1) { this[len i] = s[i]; } this.length = len s.length; } else { this[len] = s; this.length ; } } catch (e) { this[len] = s; this.length ; this.error.push("add_error : " e); } return this; }, toArray: function() { return Array.prototype.slice.call(this, 0); }, saveDoc: function(path) { this.each(function() { if (this.constructor.name == "Document") { this.saveAs(File(path)); } }); return this; }, position: 0, get: function(num) { if (typeof num == "number" && num < this.length && num >= 0) { return this[num]; } return false; }, now: function() { return this.get(this.position); }, next: function() { return this.get(this.position ); }, prev: function() { return this.get(--this.position); }, loop: function() { if (this.position > this.length) { this.position = 0 } return this.get(this.position ); }, dofunc: function(func, arg) { if (func == undefined) { return this; } var res = true; if (func.constructor.name == "Function") { res = func.call(this) } if (res) { return this; } else { return { each: function() { } }; } }, eachReverse: function(fnc, arg) { var l = this.length; var res = []; if (typeof fnc == "function") { for (var i = this.length; i > 0; i--) { ret = fnc.call(this[i], this[i], arg); typeof ret != "undefined" && res.push(ret); } } if (res.length > 0) { return doEx(res); } else { return this; } }, each: function(fnc, arg) { this.log.push("each : " this.toArray().toString()); var l = this.length; var res = []; if (typeof fnc == "function") { for (var i = 0; i < l; i = 1) { ret = fnc.call(this[i], this[i], arg); typeof ret != "undefined" && res.push(ret); } } if (res.length > 0) { return doEx(res); } else { return this; } }, filter: function() { this.log.push("filter : " Array.prototype.slice.apply(arguments).toString()); if (arguments.length == 0) { return this; } var s = { TRUE: [], FALSE: [] }; var caseBy = { function: function(arg) { while (x = this.next()) { arg(x) ? s.TRUE.push(this) : s.FALSE.push(this); } }, string: function(arg) { if (typeof this.objectShortName[arg] == "string") { arg = this.objectShortName[arg] } if (typeof this.filters[arg] == "function") { this.filters[arg].call(this, s); } else { var fd = this.attr(arg).toArray(); s.TRUE = s.TRUE.concat(fd); } } }; var extractarg = function(args) { for (var i = 0; i < args.length; i = 1) { var arg = args[i]; switch (arg.constructor.name) { case "Function": caseBy. function.call(this, arg); break; case "String": var ARG = arg.split(">"); for (var j = 0; j < ARG.length; j = 1) { caseBy.string.call(this, ARG[j]); } } } }; extractarg.call(this, arguments); try { if (s.TRUE.length > 0) { return doEx(s.TRUE); } else { var x = doEx(); for (var i in x) { x[i] = function() { alert("ERROR:Nothing!"); } } return x; } } catch (e) { this.error.push("filter_error : " e); return false; } }, find: function(text) { this.log.push("doEX_find : " text.toString()); try { var ARG = text.split(">"); var that = this; for (var i = 0; i < ARG.length; i = 1) { var SP = ARG[i].split(","); var it = doEx(); for (var j = 0; j < SP.length; j = 1) { it.add(that.attr(SP[j])); } that = it; } this.log.push("doEX_find_return : " that.toArray().toString()); return that; } catch (e) { this.error.push("find_command_error : " text); return this; } }, attr: function(x, y) { var that = this; var it = doEx(that.each(function() { try { if (typeof x == "string" && y) { try { if (typeof y == "string") { return this[x] = y; } if (typeof y == "function") { this[x] = y.call(this, this); } } catch (e) { that.error.push("attr_value_set_error " e); } } if (typeof x == "object") { for (var i in x) { if (this.hasOwnProperty(i)) { try { switch (typeof x[i]) { case "function": this[i] = x[i].call(this, this); break; default: this[i] = x[i]; } } catch (e) { that.error.push("attr_value_error : " e); } } } } if (typeof x == "string") { var gx = this[x]; try { if (gx.toString() == "") { return ""; } switch (typeof gx) { case "string": return gx; case "number": return gx; case "function": return x " is function"; case "undefind": return undefined; } if (gx.length) { return app.name.match(/InDe/) ? Array.prototype.slice.call(gx, 0) : Array.prototype.slice.call(gx, 0); } else { return gx; } } catch (e) { that.error("attr_value_error_x : " e); return false; } } if (!x && !y) { for (var i in this) { try { this.hasOwnProperty(i) && $.writeln(i " : " this[i]); } catch (e) { that.error.push("attr_value_error : " e); } } } } catch (e) { that.error.push("attr_error_ :" e); return false; } })).toArray(); var rt = []; while (r = it.shift()) { rt = rt.concat(r) } return doEx(rt); }, search: function(x, y) { return doEx(this.each(function() { if (typeof this[x] == "string") { if (this[x] == y) { return this; } } if (typeof this[x] == "object") { if (this[x].constructor.name == y) { return this; } } })); }, filters: {}, error: [], temp: [], log: [], duplicate: function(x, y) { return this.each(function() { return this.duplicate(x, y); }); }, type: function() { return this.each(function() { return this.constructor.name; }); }, debug: function() { this.each(function() { $.bp(); }); }, remove: function() { this.each(function() { this.remove(); }); }, test: function(x, fnc, arg) { typeof fnc == "function" && fnc.call(this[x], this[x], arg); }, first: function(fnc, arg) { typeof fnc == "function" && fnc.call(this[0], this[0], arg); }, constructor: { name: "DocumentObjectsExtract" }, saveLog: function() { }, alertLog: function() { alert(this.log.join("\n")); this.log = []; return this; }, alertError: function() { alert(this.error.join("\n")); this.log = []; return this; }, view: function() { var i = 0; var that = this; var O = {}; while (O = that.next()) { var D = myDialogMaker({ type: "dialog", title: "DataBrowse", opt: {}, pos: [0, 0, 400, 400], layout: [{ type: "group", name: "Group", label: "Group", pos: [0, 0, 398, 398], option: {}, items: [{ type: "edittext", name: "T", label: "", option: {}, pos: [16, 13, 386, 35] }, { type: "listbox", name: "L", label: "ListBox", pos: [15, 46, 384, 354], option: { onChange: function() { this.selection && this.parent.items.T.text = this.selection.key " : " this.selection.value; }, onDoubleClick: function() { if (this.selection) { doEx(O[this.selection.key]).view(); } } } }, { type: "statictext", name: "OT", label: "", pos: [16, 363, 200, 387], option: {} }, { type: "button", name: "E", label: "Next", pos: [250, 363, 300, 387], option: { onClick: function() { this.parent.parent.close(); } } }, { type: "button", name: "E", label: "Close", pos: [320, 363, 387, 387], option: { onClick: function() { this.parent.parent.close(2); } } }, { type: "button", name: "E", label: "Load", pos: [200, 363, 250, 387], option: { onDraw: function() { this.parent.items.OT.text = O.toString() "[" i.toString() "] of " that.length; var L = this.parent.items.L; L.removeAll(); for (var v in O) { try { var x = L.add("item", v " : " O[v].toString().slice(0, 40)); x.key = v; x.value = O[v].toString(); } catch (e) { var x = L.add("item", v " : " e); x.key = v; } } } } }] }] }); D.wD.center(); if (D.wD.show() == 2) { break; } i ; } return this; }, hvg: function(Sc) { if (!Sc) { Sc = 1 } if (app.name == "Adobe Illustrator") { var rulerOrigin_Original = app.activeDocument.rulerOrigin; app.activeDocument.rulerOrigin = [-9600, -9600]; } var hvgObject = { group: [], p_x: 0, p_y: 0, getItem: function(y, x) { try { return this.group[y][x]; } catch (e) { return false; } }, next: function() { if (this.group[this.p_y].length > this.p_x) { var get = this.getItem(this.p_y, this.p_x); this.p_x ; } else { this.p_y ; this.p_x = 0; if (this.group.length > this.p_y) { var get = this.getItem(this.p_y, this.p_x); this.p_x ; } else { return false; } } if (get.toString() == "[object Object]") { get = this.next() } return get; }, rotate: function() { var temp = []; for (var i = 0; i < hvgObject.group.length; i = 1) { hvgObject.group[i].reverse(); for (var j = 0; j < hvgObject.group[i].length; j = 1) { if (!temp[j]) { temp.push([]); } temp[j].push(hvgObject.group[i][j]); } } hvgObject.group = temp; return this; }, reverse: function() { var temp = []; for (var i = 0; i < hvgObject.group.length; i = 1) { hvgObject.group[i].reverse(); } return this; }, each: function(fnc, args) { if (typeof fnc == "function") { while (i = this.next()) { fnc.call(i, i, args) } } this.p_x = 0; this.p_y = 0; return this; }, getRows: function() { return doEx(this.group); }, getAll: function() { var o = []; while (i = this.next()) { o.push(i) } return o; }, doEx: function() { return doEx(this.getAll()); }, toArray: function() { return this.getAll(); }, view: function() { var x = this.group; var p = []; for (var i = 0; i < x.length; i = 1) { var v = []; for (var j = 0; j < x[i].length; j = 1) { v.push(x[i][j].toString() !== "[object Object]" ? "■" : "□"); } p.push(v.join("")); } alert("print\n" p.join("\n")); return this; } }; var orderFunc = { o: function(a, b) { return a.geometricBounds[0] - b.geometricBounds[0]; }, g: function(a, b) { return b.n - a.n; }, h: function(x) { return Math.abs(x.geometricBounds[1] - x.geometricBounds[3]); }, c: function(x) { var z = (x.visibleBounds[3] x.visibleBounds[1]) / 2; return z; } }; var hl = 0; this.each(function() { try { if (this.hasOwnProperty("geometricBounds")) { hl = orderFunc.h(this); } } catch (e) { } }); hl = hl / this.length; var group = []; this.each(function() { try { if (!this.hasOwnProperty("geometricBounds")) { return; } var ic = orderFunc.c(this); for (var i = 0; i < group.length; i = 1) { if (Math.abs(ic - group[i].n) < (hl * Sc)) { group[i].item.push(this); return; } } group.push({ n: ic, item: [this] }); return; } catch (e) { return e; } }); var temp = []; group = group.sort(orderFunc.g); for (var i = 0; i < group.length; i = 1) { temp.push(group[i].item.sort(orderFunc.o)); } var getCol = function() { var temp2 = []; var col = []; for (var i = 0; i < temp.length; i = 1) { var wl = {}; try { wl = temp[i].shift(); col.push(wl); } catch (e) { col.push(wl); } } var cl = 0; var ml = undefined; for (var i = 0; i < col.length; i = 1) { try { if (!ml) { ml = col[i].visibleBounds[0]; cl = Math.abs((col[i].visibleBounds[2] col[i].visibleBounds[0]) / 2); } if (col[i].visibleBounds[0] < ml) { ml = col[i].visibleBounds[0]; cl = Math.abs((col[i].visibleBounds[2] col[i].visibleBounds[0]) / 2); } } catch (e) { } } for (var i = 0; i < col.length; i = 1) { try { if (Math.abs(((col[i].visibleBounds[2] col[i].visibleBounds[0]) / 2) - cl) < Math.abs(col[i].visibleBounds[2] - col[i].visibleBounds[0])) { temp2.push(col[i]); } else { temp2.push({}); temp[i].unshift(col[i]); } } catch (e) { temp2.push({}); } } return temp2; }; var getL = function() { var l = 0; try { for (var i = 0; i < temp.length; i = 1) { l = temp[i].length; } } catch (e) { } return l; }; var temp3 = []; while (getL()) { temp3.push(getCol()); } var temp4 = []; for (var i = 0; i < temp3.length; i = 1) { for (var j = 0; j < temp3[i].length; j = 1) { if (!temp4[j]) { temp4.push([]) } temp4[j].push(temp3[i][j]); } } hvgObject.group = temp4; if (app.name == "Adobe InDesign") { hvgObject = hvgObject.rotate().rotate().rotate() } if (app.name == "Adobe Illustrator") { app.activeDocument.rulerOrigin = rulerOrigin_Original } return hvgObject; }, isPlural: function() { var pluralWords = ["ArtStyles", "Artboards", "Brushes", "CharacterStyles", "Characters", "CompoundPathItems", "DataSets", "Documents", "GradientStops", "GraphItems", "GroupItems", "InsertionPoints", "Layers", "LegacyTextItems", "Lines", "MashItems", "NonNativeItems", "PageItems", "ParagraphStyles", "PathItems", "PathPoints", "Patterns", "PlacedItems", "PluginItems", "RasterItems", "Spots", "Stories", "Swatches", "SymbolItems", "Symbols", "Tags", "TextFonts", "TextFrameItems", "TextRanges", "Variables", "Views", "Words"]; } }; doEx.extend = function(target, source) { for (var property in source) { try { target.prototype[property] = source[property]; } catch (e) { target[property] = source[property]; } } return target; }; doEx.prototype.init.prototype = doEx.prototype; doEx.view = function() { doEx(app.activeDocument).view(); }; var config_for_illustrator = { filters: { ParentisLayer: function(s) { this.each(function() { if (this.parent.constructor.name == "Layer") { s.TRUE.push(this) } }); return s; }, layers: function(s) { this.each(function() { this.constructor.name.match(/Document|Layer/) && doEx(this.layers).each(function() { s.TRUE.push(this); }); }); return s; }, placedItems: function(s) { this.each(function(a) { a.constructor.name == "PlacedItem" ? s.TRUE.push(a) : (a.constructor.name == "GroupItem" ? doEx(a.pageItems).each(arguments.callee) : s.FALSE.push(a)); }); return s; }, rasterItems: function(s) { this.each(function(a) { a.constructor.name == "RasterItem" ? s.TRUE.push(a) : (a.constructor.name == "GroupItem" ? doEx(a.pageItems).each(arguments.callee) : s.FALSE.push(a)); }); return s; }, pathItems: function(s) { this.each(function(a) { a.constructor.name == "PathItem" ? s.TRUE.push(a) : (a.constructor.name.match(/CompoundPathItem|GroupItem/) ? doEx(a.constructor.name == "GroupItem" ? a.pageItems : a.pathItems).each(arguments.callee) : s.FALSE.push(a)); }); return s; }, compoundPathItems: function(s) { this.each(function(a) { a.constructor.name == "CompoundPathItem" ? s.TRUE.push(a) : (a.constructor.name == "GroupItem" ? doEx(a.pageItems).each(arguments.callee) : s.FALSE.push(a)); }); return s; }, pathPoints: function(s) { this.filter("pathItems").each(function() { s.TRUE = s.TRUE.concat(Array.prototype.slice.call(this.pathPoints, 0)); }); return s; }, groupItems: function(s) { this.each(function() { if (this.constructor.name == "GroupItem") { s.TRUE.push(this); } else { if (this.constructor.name.match(/Document|Layer/)) { doEx(this.groupItems).each(function() { if (this.parent.constructor.name == "Layer") { s.TRUE.push(this) } }); } } }); return s; }, textFrames: function(s) { this.each(function(a) { a.constructor.name == "TextFrame" ? s.TRUE.push(a) : (a.constructor.name == "GroupItem" ? doEx(a.pageItems).each(arguments.callee) : s.FALSE.push(a)); }); return s; }, textRanges: function(s) { this.each(function() { if (this.constructor.name == "TextRange") { s.TRUE.push(this); return; } this.constructor.name.match(/TextFrame|Story/) && doEx(this.textRanges).each(function(tr) { s.TRUE.push(tr); }); }); return s; }, selection: function(s) { this.each(function() { this.selected == true || this.selected == "PathPointSelection.ANCHORPOINT" ? s.TRUE.push(this) : s.FALSE.push(this); }); return s; } }, objectShortName: { I: "allPageItems", T: "textFrames", G: "groupItems", P: "pathItems", PP: "pathPoints", S: "selection", PL: "placedItems", L: "layers", R: "rasterItems" } }; var config_for_indesign = { filters: { selection: function(s) { }, allPageItems: function(s) { this.each(function() { doEx(this.allPageItems).each(function() { s.TRUE.push(this); }); }); return s; }, groupItems: function(s) { this.each(function() { this.constructor.name == "Group" ? s.TRUE.push(this) : s.FALSE.push(this); }); return s; }, textFrames: function(s) { if (this.constructor.name !== "DocumentObjectsExtract") { return s; } this.each(function() { try { this.constructor.name == "TextFrame" ? s.TRUE.push(this) : (this.constructor.name == "Group" ? doEx(this.textFrames).each(function() { s.TRUE.push(this); }) : s.FALSE.push(this)); } catch (e) { } }); return s; }, paragraphs: function(s) { var textFrames = this.filters.textFrames.call(this, { TRUE: [], FALSE: [] }); doEx(textFrames.FALSE).each(function() { this.constructor.name == "Text" || this.constructor.name == "TextColumn" || this.constructor.name == "Paragraph" || this.constructor.name == "Cell" && textFrames.TRUE.push(this); this.constructor.name == "Table" && doEx(this.cells).each(function() { textFrames.TRUE.push(this); }); }); doEx(textFrames.TRUE).each(function() { doEx(this.paragraphs).each(function() { s.TRUE.push(this); }); }); return s; }, words: function(s) { var textFrames = this.filters.textFrames.call(this, { TRUE: [], FALSE: [] }); doEx(textFrames.FALSE).each(function() { this.constructor.name == "Text" || this.constructor.name == "TextColumn" || this.constructor.name == "Paragraph" || this.constructor.name == "Cell" && textFrames.TRUE.push(this); this.constructor.name == "Table" && doEx(this.cells).each(function() { textFrames.TRUE.push(this); }); }); doEx(textFrames.TRUE).each(function() { doEx(this.words).each(function() { s.TRUE.push(this); }); }); return s; }, characters: function(s) { var textFrames = this.filters.textFrames.call(this, { TRUE: [], FALSE: [] }); doEx(textFrames.FALSE).each(function() { this.constructor.name == "Text" || this.constructor.name == "TextColumn" || this.constructor.name == "Paragraph" || this.constructor.name == "Cell" && textFrames.TRUE.push(this); this.constructor.name == "Table" && doEx(this.cells).each(function() { textFrames.TRUE.push(this); }); }); doEx(textFrames.TRUE).each(function() { doEx(this.characters).each(function() { s.TRUE.push(this); }); }); return s; }, tables: function(s) { var textFrames = doEx(this).filters.textFrames.call(this, { TRUE: [], FALSE: [] }); doEx(textFrames.FALSE).each(function() { if (this.constructor.name == "Table" || this.constructor.name == "Cell") { this.constructor.name == "Cell" && this.tables.length > 0 && textFrames.TRUE.push(this); s.TRUE.push(this); } }); doEx(textFrames.TRUE).each(function() { doEx(this.tables).each(function() { var innertable = doEx(this).filters.tables.call(this.cells, { TRUE: [], FALSE: [] }); doEx(innertable.TRUE).each(function() { this.constructor.name == "Table" && s.TRUE.push(this); }); s.TRUE.push(this); }); }); return s; }, cells: function(s) { var tables = this.filters.tables.call(this, { TRUE: [], FALSE: [] }); doEx(tables.TRUE).each(function() { doEx(this.cells).each(function() { s.TRUE.push(this); }); }); return s; }, rows: function(s) { var tables = this.filters.tables.call(this, { TRUE: [], FALSE: [] }); doEx(tables.TRUE).each(function() { doEx(this.rows).each(function() { s.TRUE.push(this); }); }); return s; } }, objectShortName: { I: "pageItems", T: "textFrames", G: "groupItems", P: "pathItems", PP: "pathPoints", S: "selection", PL: "placedItems", L: "layers", R: "rasterItems" } }; function getObjextX(objectType) { var X = []; for (var x = 0; x < app.activeDocument.layers.length; x = 1) { X.concat(Array.prototype.slice.call(app.activeDocument.layers[x][objectType], 0)); } return doEx(X); } doEx.extend(doEx, { concat: Array.prototype.concat }); if (app.name == "Adobe Illustrator") { doEx.extend(doEx, config_for_illustrator); for (var i in config_for_illustrator.filters) { doEx.prototype[i] = doEx.prototype.filter.curry(i); } } if (app.name == "Adobe InDesign") { doEx.extend(doEx, config_for_indesign); for (var i in config_for_indesign.filters) { doEx.prototype[i] = doEx.prototype.filter.curry(i); } } }(); function() { var setPosition = function(a, b) { return [a[0] b[0], a[1] b[1], a[2] b[2], a[3] b[3]]; }; extend = function(target, source) { try { for (var property in source) { try { target.prototype[property] = source[property]; } catch (e) { target[property] = source[property]; } } } catch (e) { } return target; }; myDialogMaker = function(option) { return new myDialogMaker.prototype.init(option); }; myDialogMaker.prototype = { init: function(option) { if (!option) { var F = File.openDialog(); F.open("r"); eval("option = " F.read()); F.close(); } this.wD = new Window(option.type, option.title, option.pos, option.properties); extend(this.wD, option.option); option.layout.length > 0 && this.items = this.buildLayout(this.wD, option.layout); return this; }, dialog: function(wD, pos, Config) { var D = new Window("dialog", Config.label, Config.pos, Config.option); try { Config.layout.length > 0 && D.items = this.buildLayout(D, Config.layout); } catch (e) { } D.parents = wD; return D; }, statictext: function(wD, pos, Config) { var sT = wD.add("statictext", pos, Config.label, {}); return sT; }, edittext: function(wD, pos, Config) { if (Config.width && Config.height && Config.size) { if (Config.label) { var sT = this.statictext(wD, setPosition([0, 3, Config.width - (Config.size * 10), 20], pos), Config) } var sET = wD.add(Config.type, setPosition([Config.width - (Config.size * 10), 0, Config.width, Config.height], pos), Config. default, { name: Config.name }); } else { var Size = 0; if (Config.label) { Size = Config.label.length; var sT = this.statictext(wD, [pos[0], pos[1], (pos[0] * 1) (Size * 10), pos[3]], Config); } var sET = wD.add(Config.type, [(pos[0] * 1) (Size * 10), pos[1], pos[2], pos[3]], Config. default, Config.option); } extend(sET, Config.option); return sET; }, checkbox: function(wD, pos, Config) { var cB = wD.add("checkbox", [pos[0], pos[1], (pos[2] * 1) (Config.label.length * 10), pos[3]], Config.label); extend(cB, Config.option); return cB; }, checkboxies: function(wD, pos, Config) { var GP = wD.add("group", pos, Config.label); switch (typeof Config.list) { case "object": for (var x in Config.list) { this.checkbox(GP, checkpos, Config.list[x]); } break; } return GP; }, radiobutton: function(wD, pos, Config) { var RB = wD.add("radiobutton", pos, Config.label); extend(RB, Config.option); return RB; }, button: function(wD, pos, Config) { var bT = wD.add("button", pos, Config.label, { name: Config.name }); extend(bT, Config.option); return bT; }, iconbutton: function(wD, pos, Config) { try { var SI = ScriptUI.newImage(Config.label); var iB = wD.add("iconbutton", pos, SI); extend(iB, Config.option); return iB; } catch (e) { return this.button(wD, pos, Config); } }, dropdownlist: function(wD, pos, Config) { var ddl = wD.add("dropdownlist", pos); Config.list && this.addListItems(ddl, Config.list); ddl.selection = ddl.items[0]; extend(ddl, Config.option); return ddl; }, treeview: function(wD, pos, Config) { var TB = wD.add("treeview", pos, ""); Config.list && this.addListItems(TB, Config.list); extend(TB, Config.option); return TB; }, listbox: function(wD, pos, Config) { var TB = wD.add("listbox", pos, ""); Config.list && this.addListItems(TB, Config.list); extend(TB, Config.option); return TB; }, flashplayer: function(wD, pos, Config) { var FP = wD.add("flashplayer", pos); extend(FP, Config.option); return FP; }, progressbar: function(wD, pos, Config) { var PB = wD.add("progressbar", pos); extend(PB, Config.option); return PB; }, addListItems: function(TG, LIST) { switch (LIST.constructor.name) { case "Function": LIST(TG); break; case "Array": for (var x in LIST) { TG.add("item", LIST[x]); } break; case "Object": for (var x in LIST) { TG.add("item", x); } break; } }, slider: function(wD, pos, Config) { var SL = wD.add("slider", pos, ""); extend(SL, Config.option); return SL; }, group: function(wD, pos, Config) { var GP = wD.add("group", pos, Config.label); GP.items = this.buildLayout(GP, Config.items); extend(GP, Config.option); return GP; }, panel: function(wD, pos, Config) { var GP = wD.add("panel", pos, Config.label); GP.items = this.buildLayout(GP, Config.items); extend(GP, Config.option); return GP; }, save: function() { }, items: {}, getItem: function(name) { return this.items.hasOwnProperty(name) ? this.items[name] : false; }, temp: {}, buildLayout: function(wD, layout) { var layout_L = layout.length; var myitems = {}; for (var xi = 0; xi < layout_L; xi = 1) { var ret = myDialogMaker.prototype[layout[xi].type](wD, layout[xi].pos, layout[xi]); layout[xi].hasOwnProperty("name") && typeof layout[xi].name == "string" && myitems[layout[xi].name] = ret; } return myitems; } }; myDialogMaker.prototype.init.prototype = myDialogMaker.prototype; }(); var buildDialogLayout = myDialogMaker.prototype.buildLayout; var addListItems = myDialogMaker.prototype.addListItems; var MDM = myDialogMaker; function setFont(o, f, t, s) { var g = o.graphics; var FontStyle = { REGULAR: ScriptUI.FontStyle.REGULAR, BOLD: ScriptUI.FontStyle.BOLD, ITALIC: ScriptUI.FontStyle.ITALIC, BOLDITALIC: ScriptUI.FontStyle.BOLDITALIC }; g.font = ScriptUI.newFont(f, FontStyle[t] || ScriptUI.FontStyle.REGULAR, s); } function setFontStyle(o, f, t, s, pt, c, w) { setFont(o, f, t, s); setFGC(o, pt, c, w); } function setFGC(o, t, c, w) { try { var g = o.graphics; g.foregroundColor = g.newPen(g.PenType.SOLID_COLOR, c, w || 1); } catch (e) { } } function setBGC(o, t, c) { try { var g = o.graphics; g.backgroundColor = g.newBrush(g.BrushType.SOLID_COLOR, c); } catch (e) { } } function drawRact(target, rac) { var x = 0; var y = 0; var z = {}; try { target.graphics.newPath(); target.graphics.rectPath(rac[0], rac[1], rac[2], rac[3]); z = target.graphics.newBrush(target.graphics.BrushType.SOLID_COLOR, [rac[4][0], rac[4][1], rac[4][2], 1]); target.graphics.fillPath(z); } catch (e) { $.writeln("drawRact : " e); } } function drawRactData(target, racdata) { var x = 0; var y = 0; var z = {}; var rac = {}; try { for (var i = 0; i < racdata.length; i = 1) { rac = racdata[i]; target.graphics.newPath(); target.graphics.rectPath(rac[0], rac[1], rac[2], rac[3]); z = target.graphics.newBrush(target.graphics.BrushType.SOLID_COLOR, [rac[4][0], rac[4][1], rac[4][2], 1]); target.graphics.fillPath(z); } } catch (e) { $.writeln("drawRact : " e); } } function drawText(target, t, point) { var x = 0; var y = 0; try { x = typeof point[0] == "number" ? point[0] : 0; y = typeof point[1] == "number" ? point[1] : 0; } catch (e) { } try { target.graphics.drawString(t.text, target.graphics.newPen(target.graphics.PenType.SOLID_COLOR, [t.color[0], t.color[1], t.color[2], t.color[3]], 1), x, y, target.graphics.font); } catch (e) { } } function drawMosaicPict(target, picData, point) { var px = 0; var py = 0; try { px = typeof point[0] == "number" ? point[0] : 0; py = typeof point[1] == "number" ? point[1] : 0; } catch (e) { } try { var r = g = b = 0; var z = {}; for (var i = 0; i < picData.height; i = 1) { for (var j = 0; j < picData.width; j = 1) { target.graphics.newPath(); target.graphics.rectPath((j * picData.pictsize) px, (i * picData.pictsize) py, picData.pictsize, picData.pictsize); if (picData.type == "mono") { r = g = b = picData.data[(i * picData.width) j]; } else { r = picData.data.r[(i * picData.width) j]; g = picData.data.g[(i * picData.width) j]; b = picData.data.b[(i * picData.width) j]; } z = target.graphics.newBrush(target.graphics.BrushType.SOLID_COLOR, [r, g, b, 1]); target.graphics.fillPath(z); } } } catch (ex) { $.writeln("xxx : " ex); } } function MosaicButton(targetButtom, mozpic) { targetButtom.onDraw = function() { drawMosaicPict(this, mozpic.normal, mozpic.point); }; try { if (mozpic.mouseover) { targetButtom.addEventListener("mouseover", function(e) { e.target.onDraw = function() { drawMosaicPict(this, mozpic.mouseover, mozpic.point); }; e.target.notify("onDraw"); }, false); targetButtom.addEventListener("mouseout", function(e) { e.target.onDraw = function() { drawMosaicPict(this, mozpic.normal, mozpic.point); }; e.target.notify("onDraw"); }, false); } } catch (e) { } }

2.文本转执行

使用记事本或者notepad 等文本编辑器,将代码拷贝至文本文件,然后修改后缀名为js或者jsx,最后再illustrator软件菜单文件》脚本》其它脚本,选择脚本文件,点执行即可,也可以将脚本放在预设文件夹内,会显示再脚本下的二级子菜单。如下图所示:

illustrator图案制作教程(illustrator插件画板功能开发-多图层转多画板-js开发-ai插件)(1)

3.作者答疑

代码长度过长,如需全部项目或有疑问,请留言。

提示: 作者联系方式 提示: 插件开发流程 - 知乎

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页