Adobe Illustrator CS3〜CC2014編 選択された図形の内部情報を表示する

今回はIllustratorで選択された図形の内部情報を表示するスクリプトです。このスクリプトは開発者にとって役立つかなというもので、普通にIllustratorを使っている場合には用がないものです。IllustratorやPhotoshop、InDesignなどにはESTK (ExtendScript ToolKit) という開発環境(デバッガ)がありますが、それだけでは不便な場合もあります。特に選択された図形などのオブジェクト情報を詳細に知りたい場合は、ブレークポイントを設定してデータブラウザで確認することになります。他にもグローバル変数に入れるといった方法もありますが、実際いまいちです。
そこで、選択された複数のオブジェクト(図形)の情報をGUIで表示することができるのが以下のスクリプトです。編集エリアに出力されるので表示されたオブジェクト内容をコピーすることができます。閲覧時にはホイールマウスを使うとスムーズに内容を確認できます。

// 選択したオブジェクトの詳細な情報を表示する
(function(){
var selObj = app.activeDocument.selection;
if (selObj.length < 1){
alert("情報を表示したい対象を複数選択してから実行してください");
return;
}
// GUI
var winObj = new Window("dialog", "ステータス表示", [0, 0, 800, 640]);
winObj.add("button", [ 10, 50, winObj.frameSize.width-10, 70 ], "完了", { name : "ok" });
var statusArea = winObj.add("edittext",
[ 10, 100, winObj.frameSize.width-10, winObj.frameSize.height-40]);
var prevBtn = winObj.add("button", [10, 10, 110, 40], "前の図形");
var nextBtn = winObj.add("button", [150, 10, 250, 40], "次の図形");
var index = 0; // 選択したオブジェクト(図形)の参照番号
statusArea.text = getObjectInformation(selObj[index]);
prevBtn.onClick = function(){
index = index - 1;
if (index < 0){ index = 0; }
statusArea.text = getObjectInformation(selObj[index]);
}
nextBtn.onClick = function(){
index = index + 1;
if (index >= selObj.length){ index = selObj.length -1; }
statusArea.text = getObjectInformation(selObj[index]);
}
winObj.center();
winObj.show();
// オブジェクトの情報を取得
function getObjectInformation(obj){
var text = "";
for(var i in obj){
try{ var t = checkType(obj[i]);
}catch(e){ t = "【種類不明】"; }
try{
text = text + i + " = " + obj[i] + " | " + t + "\n";
// objectの場合
if (t == "object"){
// 1階層のみ処理する
for(var j in obj[i]){
try{ var t1 = checkType(obj[i]);
}catch(e){ t1 = "【不明】"; }
try{
text = text + "  " + j + " = " + obj[i][j] + " | " + t1 + "\n";
}catch(e){
text = text + j + "【取得不可】\n";
}
}
}
// Arrayの場合
if (t == "Array"){
for(var j=0; j<obj[i].length; j++){
var t2 = checkType(obj[i][j]);
text = text + "  "+j+":"+obj[i][j]+ " | " + t2 +"\n";
// objectの場合
if (t2 == "object"){
for(var k in obj[i][j]){
try{
text = text + "    " + k + " = " + obj[i][j][k] + "\n";
}catch(e){
text = text + k + "【取得不可】\n";
}
}
}
}
}
}catch(e){
text = text + i + " | " + t + "【取得不可】\n";
}
}
return text;
}
// オブジェクトの型を調べる
function checkType(targetObj){
//$.writeln(targetObj);
if (targetObj instanceof Array){
return "Array";
}
return typeof(targetObj);
}
})();


[サンプルをダウンロード]