ライブカラーとランダムとの狭間でスクリプツる
ライブカラーで色をつけようと思いツールを探す
いつもここに出てくるはずなんだが…。
選択しているオブジェクトで使用されている色が2種類以上ないとでてきてくれないのでした。
で、黒だけのオブジェクトから色をランダムに入れようと思ったのだけど
それは出来ないようだ。(知らないだけかも)
そこでスクリプツることに。
あんまりランダム過ぎるのもいやなので、
先に配色を用意して、グループ化されたパスにランダムに色をいれてくスクリプトを作った。
さて、気になる?スクリプトの方ですが、
イラストレーターのドキュメントに直接スクリプトを書く2で直接ドキュメントに書きつつ、記述が短くなるようにもっとスクリプトを簡単に書くためにで紹介したスクリプトの改良版(ものぐさ仕様)を使用しております。
そうです。これは手前味噌なスクリプトの紹介です。
#include "c.js"してるのはこれ。
var c = function(s,t){ return new c.prototype.init(s,t); } c.fn = c.prototype = { "init" : function (s,t) { this.length = 0; if(app.documents.length == 0)return false; switch(typeof s){ case "undefined" : return false; case "function" : return c(s()); case "string" : switch(s){ case "G" : case "groupItems": s = activeDocument.groupItems; break; case "P": case "pathItems" : s = activeDocument.pathItems; break; case "PL" : case "placedItems" : s = activeDocument.placedItems; break; case "T" : case "textFrames" : s = activeDocument.textFrames; break; case "S": case "selection" : s = activeDocument.selection; break; } break; } return this.add(s); }, }; c.extend = c.fn.extend = function(target,source) { for (var property in source) { target.prototype[property] = source[property]; } return target; } c.prototype.init.prototype = c.prototype; var extend = { "position" : 0, "g" : function(num){return this.get(num)}, "get" : function(num){ //return false; if(typeof num == "number" && num < this.length && num >= 0){ return this[num]; } return false; }, "next" : function(){ return this.get(this.position++); }, "prev": function(){ return this.get(--this.position); }, "e" : function(fnc,arg){return this.each(fnc,arg)}, "each" : function(fnc,arg) { if(typeof fnc == 'function'){ for(var i = 0;i<this.length;i++){ fnc.call(this[i],this[i],arg); }; }; return this; }, "add" : function(s){ //$.bp(); switch(typeof s.length){ case 'number' : for(var i = 0 ; i < s.length; i++)this[this.length+i] = s[i]; this.length = this.length+s.length; break; default : this[0] = s; this.length = 1; } return this; }, "f" : function(arg){return this.filter(arg)}, "filter" : function(arg){ if(!arg) return this; var s = []; if(typeof arg == "function"){ while(x = this.next()){ if(arg(x)){s.push(this);} } return c(s); } var f =function(val){ switch(val){ case "TextFrame" : case "T" : this.each(function(){ this.typename == 'TextFrame' && s.push(this); this.typename == 'GroupItem' && c(this.textFrames).each(function(){s.push(this)}); }); break; case "groupItems" : case 'G' : this.each(function(){ this.typename == 'GroupItem' && s.push(this); }); break; case "pathItems" : case "P" : this.each(function(){ var extract = function(a){ a.typename == 'PathItem' && s.push(a); a.typename == 'CompoundPathItem' && c(a.pathItems).each(function(){extract(this);}); a.typename == 'GroupItem' && c(a.pageItems).each(function(){extract(this);}); } extract(this); }); break; case "pathPoints" : case "PP": this.each(function(){ //$.bp(); var extract = function(a){ a.typename == 'PathItem' && c(a.pathPoints).each(function(){s.push(this)}); a.typename == 'CompoundPathItem' && c(a.pathItems).each(function(){extract(this);}); a.typename == 'GroupItem' && c(a.pageItems).each(function(){extract(this);}); } extract(this); }); break; case "selection" : case "S": this.each(function(){ //$.bp(); this.selected == true && s.push(this); this.selected == "PathPointSelection.ANCHORPOINT" && s.push(this); }); break; case "placedItems" : case "PL" : this.each(function(){ this.typename == "PlacedItem" && s.push(this); }); break; } } f.call(this,arg); //$.bp(); return c(s); } } c.extend(c,extend); c.extend(Array,extend);
Arrayもしっかり汚染しております。
自分の使いやすいようにこれからも改良?を続けるつもりです。
ここで公開するには、ちょっと長いような気がしてきたので、別の方法も模索中。