PageItems differences

AiScripts
2 min readApr 3, 2022

The app.activeDocument.pageItems collection gives access to all elements of the active document of different classes: paths, groups, meshes, symbols, etc. Also PageItems stores elements of a layer or group.

The main difference is that the PageItems of a document include all elements: groups and their contents, compound paths and paths inside. PageItems of layers and groups are common objects.

There are 4 elements in the document, but we see it as one object.

Often scripts use a for loop where the entire app.activeDocument.pageItems array is parsed. On large documents this will cause the script’s performance to degrade. Choosing the right array of objects allows you to speed up your scripts.

Let’s test the speed with an algorithm that locks all the objects one by one. It is enough for us to block the object array of the layer, not the document.

var doc = app.activeDocument;
for (var i = 0, len = doc.pageItems.length; i < len; i++) {
doc.pageItems[i].locked = true;
}
app.executeMenuCommand('unlockAll');
for (var i = 0, len = doc.layers[0].pageItems.length; i < len; i++) {
doc.pageItems[i].locked = true;
}
Speed test

If we use the PageItems of the document, the cycle is increased 3 times, because they are counted in parts: 1 — the compound path, 2 — the orange circle, 3 — the inner cutout triangle. The more compound paths, groups, the greater the difference in speed.

--

--

AiScripts

Sergey Osokin. Product Illustrator, Icon Designer, Script Developer (Ai, Ps). Writing about bugs and tricks in Adobe Illustrator scripts