Skip to content

Instantly share code, notes, and snippets.

@shspage
Last active July 21, 2018 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shspage/0d861dd9c9b77c5f2cfa37314b62c5c9 to your computer and use it in GitHub Desktop.
Save shspage/0d861dd9c9b77c5f2cfa37314b62c5c9 to your computer and use it in GitHub Desktop.
Adobe Illustrator script : 選択状態を配列で設定できるオブジェクト数の上限が 1000 な件
// Illustrator のスクリプトで、
// 選択状態を配列で設定できるオブジェクト数の上限が 1000 な件
// 検証
function test_1001_objects(){
// あらかじめ 1001 個のオブジェクトを選択しておく
var r = activeDocument.selection;
alert(activeDocument.selection.length); // 1001
alert(r.length); // 1001
activeDocument.selection = r;
// ... しばらく待つ ...
alert(activeDocument.selection.length); // 1000
// 最背面のオブジェクトが選択されていなかった
}
// これを回避する方法の1つは selected のプロパティを使うこと。
// この方法で 10000個のパスが選択できた。
function test_select_with_property(){
activeDocument.pageItems[0].selected = true;
}
// 選択可能数の上限がよくわからないので、安全のため検証処理を入れたりするといいのかも。
function test_warning(){
activeDocument.selection = []; // リセット
// ... 処理
if(選択されるべき数 != activeDocument.selection.length){
alert("スクリプトで選択可能なオブジェクト数の上限を超えているようです云々");
}
}
// 配列で設定したほうが速ければ配列を使う手もあるが、時間はほとんど変わらないみたいだ。
function test_time_select_with_property(){
var items = activeDocument.pageItems; // 1000個
var timer = new TimeChecker();
for(var i = 0, iEnd = items.length; i < iEnd; i++){
items[i].selected = true;
}
alert(timer.getResult()); // 27.465s
}
function test_time_select_with_array(){
var items = activeDocument.pageItems; // 1000個
var r = [];
for(var i = 0, iEnd = items.length; i < iEnd; i++){
r.push(items[i]);
}
var timer = new TimeChecker();
activeDocument.selection = r;
alert(timer.getResult()); // 28.590s
}
// 選択すべきオブジェクトを配列に入れておいて、
// 処理が最後まで正常終了した後で現在の選択範囲を解除して、
// ループを回してプロパティで選択する。
// こうすると途中でエラーが起こった場合にスクリプト実行前の
// 選択範囲を維持できるのでいいかもしれない。
// // 配列に入れられる数の上限はいくつなんだろうね。
// 以上です。
// ----
// 時間計測用
var TimeChecker = function(){
this.start_time = new Date();
this.getResult = function(){
var stop_time = new Date();
var ms = stop_time.getTime() - this.start_time.getTime();
var hours = Math.floor(ms / (60 * 60 * 1000));
ms -= (hours * 60 * 60 * 1000);
var minutes = Math.floor(ms / (60 * 1000));
ms -= (minutes * 60 * 1000);
var seconds = Math.floor(ms / 1000);
ms -= seconds * 1000;
return ("(" + hours + "h " + minutes + "m " + seconds + "s " + ms + ")");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment