もっとスクリプトを簡単に書くために
ライブラリの強化中。
こんな風に書けたら幸せになれるかしら。
c(activeDocument.groupItems).filter('selection').each( function(){ $.writeln(this.typename); }).length;
最終目標はワンライナー。(あくまでも目標です。)
c('G').f('S').e(function(){$.writeln(this.typename);});
スクリプト自体はこんな感じ。
var c = function(s){ return new c.prototype.init(s); } c.fn = c.prototype = { "init" : function (s) { if(typeof s == "undefined"){ //s = app.activeDocument.selection; $.writeln("false"); return false; } switch(typeof s.length){ case 'number' : for(var i = 0 ; i < s.length; i++)this[i] = s[i]; this.length = s.length; break; default : this[0] = s; this.length = 1; } return this; }, }; 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 = { "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; }, "filter" : function(arg){ if(!arg) return this; var s = []; var f =function(val){ switch(val){ case "TextFrame" : this.each(function(){ this.typename == 'TextFrame' && s.push(this); this.typename == 'GroupItem' && c(this.textFrames).each(function(){s.push(this)}); }); break; case "GroupItem" : this.each(function(){ this.typename == 'GroupItem' && s.push(this); }); break; case "PathItem" : this.each(function(){ this.typename == 'PathItem' && s.push(this); this.typename == 'GroupItem' && c(this.pathItems).each(function(){s.push(this)}); }); break; case "PathPoint" : this.each(function(){ this.typename == 'PathItem' && c(this.pathPoints).each(function(){s.push(this)}); this.typename == 'GroupItem' && c(this.pathItems).each(function(){c(this.pathPoints).each(function(){s.push(this)})}); }); break; case "selection" : this.each(function(){ //$.bp(); this.selected == true && s.push(this); this.selected == "PathPointSelection.ANCHORPOINT" && s.push(this); }); break; } } f.call(this,arg); return c(s); } } c.extend(c,extend); c.extend(Array,extend); //c.extend(Object,extend);
いろいろ試行錯誤中。