• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Collections vs. Arrays

Advocate ,
Sep 30, 2016 Sep 30, 2016

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

TOPICS
Actions and scripting

Views

556

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Sep 30, 2016 Sep 30, 2016

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 13, 2016 Oct 13, 2016

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Oct 13, 2016 Oct 13, 2016

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines