Copy link to clipboard
Copied
Photoshop Scripting exposes Collections, e.g.
app.documents;
app.layers;
In InDesign Scripting, these Collections behave differently from Arrays: for instance you can access items by index with negative values (e.g. pages[-1] means the last but one), etc. Moreover, looping through collections is reported to be slower, so they build Arrays out of collections and then iterate on them.
I'm trying to find out whether the same could hold true for Photoshop as well, but so far... no proofs. I'm also trying to use the Reflection interface on collections, but it doesn't seem possible (document.layers, as opposed to document.layers[0]).
Does anybody know more about the topic?
Thank you
Davide Barranca
Copy link to clipboard
Copied
Damn, Davide, I've never heard of collections, so can't offer much help, but in your example, wouldn't document.layers be an object rather than an array?
Copy link to clipboard
Copied
Actually I should have written app.activeDocument.layers (the Layers collection makes sense in the context of a Document, not the app tout-court).
The Layer collection behaves like an array (in fact you can get layers by index), but is an instanceof Object. So it's a peculiar kind of thing – apparently in InDesign the distinction is even more evident than in Photoshop...
Davide
Copy link to clipboard
Copied
I do tests for ArtLayer or LayerSet like this: (not sure if one is more expensive of a call than the other)
activeDocument.activeLayer.typename
activeDocument.activeLayer instanceof LayerSet
I just ran into this when activeDocument.activeLayer.kind returned undefined on a LayerSet. I thought I had a bug but apparently that was some design choice we made and sure enough we don't report LayerKind.GROUP or something similar.