Page 1 of 1

Scripting Multiple rectangle selection

Posted: Tue Feb 12, 2019 12:39 pm
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

Re: Scripting Multiple rectangle selection

Posted: Tue Feb 12, 2019 2:28 pm
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.

Re: Scripting Multiple rectangle selection

Posted: Wed Feb 13, 2019 5:51 am
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.