Skip to main content
Inspiring
October 27, 2021
Answered

Photoshop Scripting: linkedLayers property on layers does not seem to work.

  • October 27, 2021
  • 1 reply
  • 1145 views

I'm trying to detect if an artlayer has layers or adjustment layers linked to it.

There is the property linkedlayers that should be an array of linkers linked to this layer.

I tried this simple code on many linked layers, but the array.length is always 0.

I don't see what's wrong here...

 

var layer = app.activeDocument.activeLayer;

alert(layer.linkedLayers.length);

 

I'm using PS2020...

What I consider a linked layer for example an artlayer, with an curve adjustmentlayer linked on it. I would expect when the active layer is the artlayer, there is one linkedlayer in the array, the curve adjustment layer... or am I missing something?

This topic has been closed for replies.
Correct answer Kukurykus

I tested it, it does what you say it does. The layer object needs to be selected, but the grouped layers don't, whats at least better than my function. But I don't want the grouped layers to be ungrouped, I want an array of those grouped layers. Sometimes I just need to delete the grouped layers, other times, I just want to know if there are grouped layers. For my own learning process, I would like to know what your script actually does.. The slice.call, .pop().. it looks fuzzy to me, it's efficient for sure, but for the avarage javascripter a bit hard to read.


 

aL = activeDocument.activeLayer
grpd = [], lrs = [].slice.call(aL.parent.layers)
while(lrs.length) (((pop = lrs.pop()).itemIndex <= aL.itemIndex)
|| (pop.grouped && grpd.push(pop))) || lrs.length = 0; alert(grpd)

 

Now it pushes grouped  layers (to selected layer) to the array, alerted at end.

 

slice.call clones layers to new array. In this case it lets use while instead of for...in statement, while pop() cuts out last item from cloned array (leaving original one not affected)

1 reply

Kukurykus
Legend
October 27, 2021

You can't check in artLayer properties if there's any adjustement layer over it.

 

Ps. linkedLayers is to check an array of layer(Set)s connected by 'chain' thing.

Marvin01Author
Inspiring
October 27, 2021

Oh! Now I understand, it's for the chain thing! I mean the other linking method.

In action manager code I managed to "link/unlink" a curve to an ArtLayer.

Is there some action manager code to check if a layer is linked or not, and if posible. to what layer?

I Think I can use the index property of a layer to check the layer above it if it's linked, and asume it must be linked to the one below it. But at the very leasy, I need to know if a layer is linked or not.

Maybe I can do a try to unlink every layer and link it again, and when error it was not linked.. but that not a clean or fast way to detect a linked layer I gues.

Marvin01Author
Inspiring
October 31, 2021

The last code from me does not select any layers to check if they are grouped with other layer.

 

The only what you have to do before you run script is to have a selected layer, the one from which the other ones (over it) will be as the result ungrouped. Try it with my code first.


I tested it, it does what you say it does. The layer object needs to be selected, but the grouped layers don't, whats at least better than my function. But I don't want the grouped layers to be ungrouped, I want an array of those grouped layers. Sometimes I just need to delete the grouped layers, other times, I just want to know if there are grouped layers. For my own learning process, I would like to know what your script actually does.. The slice.call, .pop().. it looks fuzzy to me, it's efficient for sure, but for the avarage javascripter a bit hard to read.