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: xbytor, DavideBarranca, Paul MR

Post Reply
AnilTejwani
Posts: 15
Joined: Wed Feb 22, 2017 5:37 pm

Scripting Multiple rectangle selection

Post by AnilTejwani » Tue Feb 12, 2019 12:39 pm

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
multi-rect-selection-ps.png
screenshot of multiple rect selection (manual) done on PS
multi-rect-selection-ps.png (2.44 KiB) Viewed 1095 times

User avatar
Kukurykus
Posts: 195
Joined: Mon Jul 25, 2016 12:36 pm

Re: Scripting Multiple rectangle selection

Post by Kukurykus » 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]])

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 61 times

AnilTejwani
Posts: 15
Joined: Wed Feb 22, 2017 5:37 pm

Re: Scripting Multiple rectangle selection

Post by AnilTejwani » Wed Feb 13, 2019 5:51 am

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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~oO~~Oo~^~~~
http://bit.ly/photoshopScripting
http://bit.ly/ts-timeslice
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Post Reply