Skip to main content
Inspiring
July 16, 2018
Answered

how to select with intersection?

  • July 16, 2018
  • 2 replies
  • 1315 views

I don't understand how to make an intersection selection.

I tried the following code with a 600 x 800 pixels document with a simple background layer:

var originalRulerUnits = app.preferences.rulerUnits; // valeur actuelle Ruler

app.preferences.rulerUnits = Units.PIXELS;

var originalTypeUnits = app.preferences.typeUnits; // valeur actuelle prefs

app.preferences.typeUnits = TypeUnits.PIXELS;

app.activeDocument.selection.selectAll();

// trying to select a 10px "frame"

app.activeDocument.selection.select([[10, 10], [10, 780], [580,780], [580, 10] ], SelectionType.INTERSECT);

No intersection is done, new selection replaces the existing one.

Thank you for your help.

This topic has been closed for replies.
Correct answer frmorel

r-bin  schrieb

And what result did you expect?

Well, hum... my bad, It was a language problem, I wanted to DIMINISH previous selection and it works fine.

activeDocument.selection.select([[10, 10], [10, 300], [300, 300], [300,10]], SelectionType.REPLACE);

activeDocument.selection.select([[20, 20], [20, 200], [200, 200], [200,20]], SelectionType.DIMINISH);

Sorry

2 replies

Legend
July 16, 2018

fredericm80874937

No intersection is done, new selection replaces the existing one.

And what result did you expect?


pixxxelschubser
Community Expert
Community Expert
July 17, 2018

r-bin  schrieb

fredericm80874937

No intersection is done, new selection replaces the existing one.

And what result did you expect?


I think something like that

// https://forums.adobe.com/thread/2513858

// how to select with intersection?

// regards pixxxelschubser

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

var aDoc = app.documents.add (400,400);

var myColor = new SolidColor();

var Rd = myColor.rgb.red = 0;

var Gr = myColor.rgb.green = 255;

var Bl = myColor.rgb.blue = 0;

aDoc.selection.select([[150, 150], [150, 350], [350, 350], [350, 150] ]); // add

aDoc.selection.fill(myColor);

refresh();

alert("selection 1 filled");

var Rd = myColor.rgb.red = 255;

var Gr = myColor.rgb.green = 0;

var Bl = myColor.rgb.blue = 0;

aDoc.selection.select([[50, 50], [50, 250], [250, 250], [250, 50] ]); // replace by default

aDoc.selection.fill(myColor);

refresh();

alert("selection 2 filled");

var Rd = myColor.rgb.red = 0;

var Gr = myColor.rgb.green = 0;

var Bl = myColor.rgb.blue = 255;

aDoc.selection.select([[100, 100], [100, 400], [400, 400], [400, 100] ], SelectionType.INTERSECT);

aDoc.selection.fill(myColor);

alert("a new larger selection intersect with previous selection");

app.preferences.rulerUnits = originalRulerUnits;

But this is also a shot into dark.

Kukurykus
Legend
July 16, 2018

Use other selection instead of this line:

app.activeDocument.selection.selectAll();

like whatever that can be intersected:

activeDocument.selection.select([[0, 200], [50, 360], [970, 1260], [0, 500]], SelectionType.REPLACE)