#target illustrator
if (app.documents.length !== 0) {
var doc = app.activeDocument;
if (doc.selection.length = 1) {
$.hiresTimer;
var d = 1
sr = doc.selection[0]
sGB = sr.geometricBounds;
var selAreaGB = new Array();
var sel = new Array()
cab = doc.artboards[doc.artboards.getActiveArtboardIndex()].artboardRect
var rGB = getGbAb(cab, sGB)
for(i=0;i<doc.artboards.length;i++){
var abb = doc.artboards[i].artboardRect
selAreaGB[i] = [(abb[0]+rGB[0]), (abb[1]-rGB[1]), (abb[0]+rGB[2]), (abb[1]-rGB[3])];
}
sc = 0
for (p=doc.pageItems.length-1;p>=0;p--) {
if (diff1(selAreaGB, doc.pageItems[p].geometricBounds)) {
doc.pageItems[p].selected = true;
}
}
var time = $.hiresTimer/1000000;
alert (time.toFixed(2) + " seconds")
} else {
alert ("Создайте или выделите прямоугольник внутри которого необходимо выделить объекты")
};
}
function diff1(sagbArr, curItem) {
compare = false
for(i=0;i<selAreaGB.length;i++){
dGb = [(sagbArr[i][0]-curItem[0]-d), (curItem[1]-sagbArr[i][1]-d), (curItem[2]-sagbArr[i][2]-d), (sagbArr[i][3]-curItem[3]-d)]
if ((dGb[0]<0)&&(dGb[1]<0)&&(dGb[2]<0)&&(dGb[3]<0)) {
compare = true
break;
}
}
return compare
}
function getGbAb(a, o) {
var GbAb = [(o[0]-a[0]), (a[1]-o[1]), (o[2]-a[0]), (a[1]-o[3])]
return GbAb
}
function diff(r, c) {
var dGb = [(r[0]-c[0]-d), (r[1]-c[1]-d), (c[2]-r[2]-d), (c[3]-r[3]-d)]
if ((dGb[0]<0)&&(dGb[1]<0)&&(dGb[2]<0)&&(dGb[3]<0)) {
return true
} else {
return false
}
}