Copy link to clipboard
Copied
Given geometricBounds, is there a JS to select page items resting in that bound?
Thanks much..
Hi eboda_snaf,
I would create a rectangle with the geometricBounds of your "selection area".
And then do test with method intersectPath() on duplicates of all page items on the spread.
It will return an error, if the objects used do not intersect.
The core of a test with intersectPath() will be something like this:
...// Example
// Two objects on the page selected:
var objectA = app.selection[0];
var objectB = app.selection[1];
var dupA = objectA.duplicate();
var dupB = objectB.duplicate();
try
{
var result
Copy link to clipboard
Copied
Hi,
Try this snippet ...
var doc = app.documents[0];
var myPageItems = doc.allPageItems;
var myBounds = [0,0,80,80]
selectByBounds (myPageItems,myBounds)
function selectByBounds (o /*items array*/, b /*bounds array*/){
var len = myPageItems.length;
var a = new Array();
for (var j=0; j<len; j++){
// get all object inside:
if (o
.geometricBounds[0] >= b[0] && o
.geometricBounds[1] >= b[1] && o
.geometricBounds[2] <= b[2] && o
.geometricBounds[3] <= b[3]) {
a.push(o
); }
app.select(a);
}
}
Copy link to clipboard
Copied
Hi Ronald,
app.select(a) will not work for pageItems on different spreads.
And it will also not work as expected with nested objects.
( You are using the allPageItems array that is including nested objects. )
Hi boda_snaf,
do you want to simulate the behavior of a selection marquee?
That everything the marquess is touching will be selected?
Or is "selecting" for you something like "addressing" ?
Regards,
Uwe
Copy link to clipboard
Copied
hi Ronald,
i'd like to select items that are touching or within an object.
Thanks much..
i've faced a problem here, although the rotated rectangle did not touch the image physically.
The result shows otherwise if comparing and checking the geometricbounds of the two pageitems.
Copy link to clipboard
Copied
Hi eboda_snaf,
I would create a rectangle with the geometricBounds of your "selection area".
And then do test with method intersectPath() on duplicates of all page items on the spread.
It will return an error, if the objects used do not intersect.
The core of a test with intersectPath() will be something like this:
// Example
// Two objects on the page selected:
var objectA = app.selection[0];
var objectB = app.selection[1];
var dupA = objectA.duplicate();
var dupB = objectB.duplicate();
try
{
var result = dupA.intersectPath(dupB);
}
catch(e)
{
dupA.remove();
dupB.remove();
alert(e.message);
};
if(result !== undefined)
{
result.remove();
app.select(objectB);
};
Special cases you have to deal with separately:
1. Groups and perhaps group like objects like MSOs and buttons.
2. Graphic lines.
And this method will not consider stroke weights.
Regards,
Uwe
Copy link to clipboard
Copied
thank you so much..