Skip to main content
Inspiring
September 18, 2021
Question

VB.NET and Photoshop - Some existing layers aren't accessible

  • September 18, 2021
  • 2 replies
  • 267 views

I've written a VB.NET app (that hooks into Photoshop's COM) that automates setting up mock up images. The only way I could find to gain access to specific layers/art layers was to pre-format the layer names with "Layer 0", "Layer 1", etc.

 

For example:
     proofArtLayer = curDoc.ArtLayers.Item("Layer 1")
     printArtLayer = curDoc.ArtLayers.Item("Layer 2")


Now, I'm trying to work on a project that manipulates files from other people and the layer names are not pre-formatted. I've tried the previously mentioned method and it's very hit-or-miss if it works or not (usually gives 'Element doesn't exist' runtime error). My understanding was that Photoshop saw the layers as "Layer 0", "Layer 1", etc despite their actual names (what the documentation refers to as its 'itemKey').

 

The VB Script doc says:
ArtLayers
     Method                  |  Parameter Type     |  Returns      | What it does
     Item (ItemKey)     | Number   (Long)     | ArtLayer    | Gets an element from the ArtLayers collection.

 

I've tried passing numbers (to iterate through artLayers like an array), but that throws an illegal argument error.


I'm so confused. I would think there would have to be some way of directly accessing and cycling through layers without pre-formatting the layer names manually (which kind of defeats the point of automating). I just need someone more knowledge and experience to point me in the right direction.

 

Thank you so much for any help you can give!

This topic has been closed for replies.

2 replies

Inspiring
November 21, 2021

Use a for each loop to access each art layer in the document.

Stephen Marsh
Community Expert
Community Expert
September 19, 2021

Build a test file with various layers. Then use the following script to inspect each layer:

 

Active Layer Inspector.jsx

 

I created this script for my personal use.

 

Now delete and add new layers to bring you back to the same number of layers, inspect them with the script again.

 

Do the same with a Background layer and promoting the Background to a regular layer.

 

Take note of the various Item Index # vs. layer ID# values change.

 

At least with JavaScript, you can select/target a layer by name, index or ID.