出てると安心。「プログレスバー」


いつ終わるかも判らないスクリプトを只待っているのも苦痛なので。
処理状況が解るように、簡単なプログレスバーを表示できるようにしてみました。
参考にしたのは、「InDesign CS3 Guide Scripts」に入っているサンプルスクリプトの「CallProgressBar.jsx」と「ProgressBar.jsx」

progressBar.js

function CreateProgressPanel(myMaximumValue, myProgressBarWidth , progresTitle){
	myProgressPanel = new Window('window',  typeof progresTitle == 'string' ? progresTitle : 'Processing....');
	with(myProgressPanel){
		myProgressPanel.myProgressBar = add('progressbar', [12, 12, myProgressBarWidth, 24], 0, myMaximumValue);
	}
	var PP = {
		'ProgressPanel' : myProgressPanel,
		'show' : function(){this.ProgressPanel.show()},
		'hide' : function(){this.ProgressPanel.hide()},
		'max' : myMaximumValue,
		'barwidth' : myProgressBarWidth,
		'val' :  function(val){
			if(typeof val == "undefined")return this.ProgressPanel.myProgressBar.value;
			this.ProgressPanel.myProgressBar.value = val+1;
			this.show();
			this.hide();
			this.show();
			//$.writeln(this.ProgressPanel.myProgressBar.value);
	}
	}
	return PP;
}

//c.js including eachProgress
//http://svn.coderepos.org//share/platform/illustrator/javascript/lib/c.js
(function(){
	if(typeof c == 'undefined')return;
	var progress = {
	  	'eachProgress' : function(fnc,pbtitle,arg) {
	  	    var l = this.length;
	  	    var res = [];
			var ProgressPanel = CreateProgressPanel(l, 500,pbtitle);
			ProgressPanel.show();
			
			if(typeof fnc == 'function'){
			for(var i = 0;i<l;i++){
				 ret = fnc.call(this[i],this[i],arg);
				 typeof ret != "undefined" && res.push(ret); 
				 ProgressPanel.val(i);
			 }
			}
			ProgressPanel.hide();
			if(res.length > 0){
                return res;
			}else{
                return this;
		    }
   	 	}
	}
	c.extend(c,progress);
	c.extend(Object,progress);
	c.extend(Array,progress);
})();


使い方:

#include 'progressBar.js'
var ProgressPanel = CreateProgressPanel(500, 500,'処理中…');
ProgressPanel.show(); //プログレスバーを表示
for(var i = 0;i<500;i++){
            .
            .
            .//処理
            .
	     ProgressPanel.val(i); //
		}
ProgressPanel.hide(); //プログレスバーを片付ける

c.jsを使った場合

//http://svn.coderepos.org//share/platform/illustrator/javascript/lib/c.js
#include 'c.js'
#include 'progressBar.js'
c(app.activeDocument.selection).eachProgress(function(){this.remove()},'処理中…');

イラストレーターだとうまくうごかなかったのを修正しました。