The web showed me no clues, while

I was trying to figure out how to simulate a brush click - via function that takes a 'Point' as argument:

Code: Select all

```
// SimulateBrushClick([200, 200])
function SimulateBrushClick (Pt)
{
var docRef = app.activeDocument;
docRef.pathItems.removeAll()
var arrPathPt = new Array()
var arrSubPathPt = new Array()
arrPathPt[0] = new PathPointInfo
arrPathPt[0].kind = PointKind.CORNERPOINT
arrPathPt[0].anchor = Pt
arrPathPt[0].leftDirection = arrPathPt[0].anchor
arrPathPt[0].rightDirection = arrPathPt[0].anchor
arrSubPathPt[0] = new SubPathInfo()
arrSubPathPt[0].operation = ShapeOperation.SHAPEXOR
arrSubPathPt[0].closed = false
arrSubPathPt[0].entireSubPath = arrPathPt
var myPathItem = docRef.pathItems.add("PathItemName", arrSubPathPt);
myPathItem.strokePath(ToolType.PENCIL) // BRUSH
}// function SimulateBrushClick
```

Problem is that if I construct such points array of say 1000 items inside - [x, y] subarrays

The SimulateBrushClicks function becomes

**too slow**, at evaluating

Code: Select all

```
docRef.pathItems.removeAll() // in order to remove the previous 1000 points
and
docRef.pathItems.add("PathItemName" + i, arrSubPathPt); // in order to add 1000 named paths.(it even breaks the evaluation on the 999th element)
```

• the construction of the 1000+ items points array is slow (2-3 minutes), [via PtArr.push(Array(x, y));] // ASIDE PROBLEM

• then the iteration over it and placing the brush clicks (2-3 minutes) -

*since I literally watch how the script places them one by one, and not instantly placing them.*

So my questions are:

• are there any alternatives/possibilites to my aproach - in order to place/click with the brush at given coordinates?

• is this the best method to use? - if so whats the reason and the advantages of adding a named path to the pathitems collection?

BTW, Heres a sample on how I would generate the points array -

Code: Select all

```
// SimulateBrushClicks(PointGrid(50, 50));
function PointGrid (incW, incH)
{
var PtArr = new Array();
var dw = (parseInt(app.activeDocument.width) / incW);
var dh = (parseInt(app.activeDocument.height) / incH);
var dstW = 0;
var dstH = 0;
for (i = 0; i < (1 + incW); i++)
{
dstH = 0;
for (j = 0; j < (1 + incH); j++)
{
PtArr.push(Array(dstW, dstH));
dstH = dstH + dh;
}// for
dstW = dstW + dw;
}// for
return PtArr;
}// function PointGrid
```