• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JS to select objects at a predefined boundaries?

Participant ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

Given geometricBounds, is there a JS to select page items resting in that bound?

Thanks much..

TOPICS
Scripting

Views

595

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 02, 2017 Apr 02, 2017

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

...

Votes

Translate

Translate
Enthusiast ,
Apr 01, 2017 Apr 01, 2017

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);

     }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 01, 2017 Apr 01, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 02, 2017 Apr 02, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2017 Apr 02, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 02, 2017 Apr 02, 2017

Copy link to clipboard

Copied

LATEST

thank you so much..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines