Copy link to clipboard
Copied
Hi all,
I have many layerSets and each layer set contains two art layers, I want to provide/set the unique IDs/key to all these layers such that each art layer of a particular layerset have same ID.
After this, I have to randomly move the art layers from one layer set to another and find the pairs of art layers. For this, I need to get the unique IDs/Key back.
So, Is there any way to set and get the unique ID/Key to a layer or layer set?
Thanks In advance,
_VG.
Copy link to clipboard
Copied
You can not set it but Photoshop already has a unique ID of each layer in a document.
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "LyrI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
executeActionGet(ref).getInteger(charIDToTypeID( "LyrI" ));
The exception is the background layer. It will always be 0 if there is only a background layer and 1 if there are other layers.
Copy link to clipboard
Copied
Thanks for the reply Michael..
If we have the unique ID of a layer then how do we retreive the layer back?
Copy link to clipboard
Copied
If the layer names are also unique you can get the layer name.
function getLayerNameByLayerID(id) {
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Nm " ));
ref.putIdentifier( charIDToTypeID( "Lyr " ), id );
return executeActionGet(ref).getString(charIDToTypeID( "Nm " ));;
}
If the names are not unique you could make the layer active by ID
function makeActiveByID( id ){
try{
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putIdentifier( charIDToTypeID( "Lyr " ), id );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
return activeDocument.activeLayer;
}catch(e){}
}
Copy link to clipboard
Copied
Thanks for the help Michael.
But Is there any way or work around to set/store any value to the layer and retreive it back later?
May be it have any property or something in which we can store the value and identify the layer by using this value later.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now