Get layer with ID

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

Moderators: xbytor, DavideBarranca, Paul MR

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

Get layer with ID

Post by csuebele » Wed Oct 02, 2019 4:09 pm

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: 220
Joined: Mon Jul 25, 2016 12:36 pm

Re: Get layer with ID

Post by Kukurykus » Wed Oct 02, 2019 4:28 pm

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 » Wed Oct 02, 2019 4:39 pm

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: 220
Joined: Mon Jul 25, 2016 12:36 pm

Re: Get layer with ID

Post by Kukurykus » Wed Oct 02, 2019 5:53 pm

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 » Wed Oct 02, 2019 8:20 pm

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: 220
Joined: Mon Jul 25, 2016 12:36 pm

Re: Get layer with ID

Post by Kukurykus » Thu Oct 03, 2019 3:20 pm


Post Reply