Scripting Multiple rectangle selection

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

AnilTejwani
Posts: 20
Joined: Wed Feb 22, 2017 5:37 pm
Location: Paraguay

Scripting Multiple rectangle selection

Post by AnilTejwani »

Hi,

Is it possible to make multiple selection and then fill it? (its not a continous selection, its multiple squares/rectangles and they dont overlap)

Manually I would select a rectangle, then use 'shift' and make second selection, use 'shift' again and make next selection... [refer attachment]

Code: Select all


var ad = app.activeDocument;
ad.selection.select([ [0,0], [0,10], [10,10], [10,0] ]); // first square
ad.selection.select([ [20,20], [20,30], [30,30], [30,20] ]); // second square
...
ad.selection.select([ [200,200], [200,230], [230,230], [230,200] ]); // nth square
ad.selection.fill( app.foregroundColor);
Thanks in advance
Attachments
screenshot of multiple rect selection (manual) done on PS
screenshot of multiple rect selection (manual) done on PS
multi-rect-selection-ps.png (2.44 KiB) Viewed 3543 times
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Scripting Multiple rectangle selection

Post by Kukurykus »

Code: Select all

function slctn() {
sel = (aD = activeDocument).selection
for(i = 0; i < (arg = arguments).length;) {
sel.select(arg[i++], SelectionType.EXTEND)
}
sel.fill(foregroundColor), sel.deselect()
}

slctn([[0,0], [0,10], [10,10], [10,0]], [[20,20],
[20,30], [30,30], [30,20]], [[200,200],
[200,230], [230,230], [230,200]])

Unfortunately after one update this forum doesn't have indentations, so each line of above script start from the same position what makes it unreadable. Btw it seems I'm the last who answer on this forum - it's almost dead :D I sent you PM - check this out.
Attachments
Making and Filling the Square Selections.rar
(455 Bytes) Downloaded 311 times
AnilTejwani
Posts: 20
Joined: Wed Feb 22, 2017 5:37 pm
Location: Paraguay

Re: Scripting Multiple rectangle selection

Post by AnilTejwani »

Kukurykus wrote: Tue Feb 12, 2019 2:28 pm

Code: Select all

function slctn() {
sel = (aD = activeDocument).selection
for(i = 0; i < (arg = arguments).length;) {
sel.select(arg[i++], SelectionType.EXTEND)
}
sel.fill(foregroundColor), sel.deselect()
}

slctn([[0,0], [0,10], [10,10], [10,0]], [[20,20],
[20,30], [30,30], [30,20]], [[200,200],
[200,230], [230,230], [230,200]])
That's perfect, thanks a lot Kukurykus.