Page 1 of 1
Get layer with ID
Posted: Wed Oct 02, 2019 4:09 pm
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.
Re: Get layer with ID
Posted: Wed Oct 02, 2019 4:28 pm
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:
Re: Get layer with ID
Posted: Wed Oct 02, 2019 4:39 pm
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.
Re: Get layer with ID
Posted: Wed Oct 02, 2019 5:53 pm
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.
Re: Get layer with ID
Posted: Wed Oct 02, 2019 8:20 pm
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.
Re: Get layer with ID
Posted: Thu Oct 03, 2019 3:20 pm
by Kukurykus
Re: Get layer with ID
Posted: Thu Nov 28, 2019 10:14 am
by dharya
Good explaination.
Re: Get layer with ID
Posted: Sat Jul 11, 2020 5:41 am
by Shrushti6636
Thank you for your help. I'm looking for something like that