Get layer with ID

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

csuebele
Posts: 4
Joined: Thu Jan 01, 1970 12:00 am

Get layer with ID

Post by csuebele »

I want to get a layer using the layer's ID, but I don't want to make the layer active. I just want to be able to create a variable for the layer, where I can use DOM code to get the layer's parent.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Get layer with ID

Post by Kukurykus »

Code: Select all

id = activeDocument.activeLayer.id

//	some code

sTT = stringIDToTypeID;
(ref = new ActionReference()).putIdentifier(sTT('layer'), id)
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref)
executeAction(sTT('select'), dsc)

The above is to check active layer id, that later can be used to select that layer by Action Manager. When it's selected you may check its parent:

Code: Select all

activeDocument.activeLayer.parent
csuebele
Posts: 4
Joined: Thu Jan 01, 1970 12:00 am

Re: Get layer with ID

Post by csuebele »

Thanks, but can I get the layer without making it active? I have the layer IDs, I just need to check the layer's what the layer's parent is, without making the layer active, as that will slow down the script too much.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Get layer with ID

Post by Kukurykus »

Make a loop over layers, where each of them will be compared to id you know. If they are of same value then check its parent and break a loop.
csuebele
Posts: 4
Joined: Thu Jan 01, 1970 12:00 am

Re: Get layer with ID

Post by csuebele »

I'm not sure that will work in my case. I have a list of layersets that I want to exclude and I have a list of all layers - all by ID. I need to create an array of all the layers with certain attributes, but which are not in the omitted layersets. So I did have a loop, but to check to see if a layer is a child of one of these layersets, I have to make it active, using the layer ID. I didn't really want to have to make it active.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Get layer with ID

Post by Kukurykus »

dharya
Posts: 1
Joined: Thu Nov 28, 2019 10:08 am

Re: Get layer with ID

Post by dharya »

Good explaination.
Shrushti6636
Posts: 1
Joined: Sat Jul 11, 2020 5:39 am

Re: Get layer with ID

Post by Shrushti6636 »

Thank you for your help. I'm looking for something like that