Do you know how to query the "real" visibility of a layer using AM ?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

anduvo
Posts: 4
Joined: Tue Oct 12, 2021 9:02 pm

Do you know how to query the "real" visibility of a layer using AM ?

Post by anduvo »

Hi Everyone,

I've run into this unexpected behavior when you ask the visibility of a layer via AM:
Suppose you have a layerset and inside that layerset a layer, both visible.
If you hide the layerset, then the layer also becomes invisible, which is normal, and it's eye icon turns grey.

If you query the visibility of the layer via the DOM, you will get false as expected:

Code: Select all

activeDocument.activeLayer.visible
result --> false

but if you query the visibility with AM, then you get true.

Code: Select all

var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Vsbl" ));
ref.putIndex( charIDToTypeID( "Lyr " ), 1);
executeActionGet(ref).getBoolean(charIDToTypeID( "Vsbl" ));
result --> true

Because I am working on very large documents I need AM for speed. The problem is that if I want to know the "real" visibility of the layer via AM, I am also needing to query the visibility of their parents each time and this is causing lots of extra calculations lowering down considerably the performance of the script.

I don't know if this is really a bug; seems an intended behavior, maybe I am just missing how to properly query the visibility with AM.

Do you know how to query the "real" visibility of a layer using AM ?
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Do you know how to query the "real" visibility of a layer using AM ?

Post by Kukurykus »

The indexes change when checking visibility of layers. You must include presence of (no) background to refer to adequate index.
anduvo
Posts: 4
Joined: Tue Oct 12, 2021 9:02 pm

Re: Do you know how to query the "real" visibility of a layer using AM ?

Post by anduvo »

Hi Kukurykus,

Using the index was just for the example; although when using it I do take into account the presence or not of a background.

It happens the same if I use the ID instead:

Code: Select all

ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
var desc = executeActionGet(ref);
var layerVisibility = desc.getInteger(charIDToTypeID('Vsbl'));
layerVisibility gets 1 with this code although the layer is not visible (greyed eye) and it normally should be getting 0
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Do you know how to query the "real" visibility of a layer using AM ?

Post by Kukurykus »

That is no matter you use index or identifier, in both cases you must take into account the background.
anduvo
Posts: 4
Joined: Tue Oct 12, 2021 9:02 pm

Re: Do you know how to query the "real" visibility of a layer using AM ?

Post by anduvo »

Actually it has nothing to do with having a background layer or not
if you don't believe me please try it yourself:

1) create a layerSet
2) create a layer inside that layerSet
3) hide the layerSet

4) select the layer and query visibility using the DOM = you will get false (which is expected)
5) query the layer visibility with AM either by index or ID = you will get 1 (true) (which is unexpected)
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Do you know how to query the "real" visibility of a layer using AM ?

Post by Kukurykus »

I assume you don't want to check indexes / identifiers for active layers so you must to loop over them, but remembering about background layer.
Since Action Manager refers to layer panel items visibility, you can always check container 'eye' status for any layer that's inside:

Code: Select all

sTT = stringIDToTypeID;
(ref = new ActionReference()).putEnumerated
(sTT('layer'), sTT('ordinal'), sTT('targetEnum'))
executeActionGet(ref).getInteger(sTT('parentLayerID')) 
anduvo
Posts: 4
Joined: Tue Oct 12, 2021 9:02 pm

Re: Do you know how to query the "real" visibility of a layer using AM ?

Post by anduvo »

yes, as I mentioned in the original post, I am doing that already, I am checking the visibility of the parent(s) of each layer and that is adding too much time to the script when dealing with big files.

So I thought there was maybe a more direct way to know the layer visibility without the need to check the parents visibility (using AM not the DOM).
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Do you know how to query the "real" visibility of a layer using AM ?

Post by Kukurykus »

I think doing that by AM for just one layer in each layer set you are going to look into, is still faster than doing that by DOM without checking visibility of layers parent (that surely is shorter but longer for complex structrure of layers when using Document Oriented Object).