Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to set and get key/ID to a particular layer.

Participant ,
Aug 12, 2013 Aug 12, 2013

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.

TOPICS
Actions and scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guru ,
Aug 12, 2013 Aug 12, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 12, 2013 Aug 12, 2013

Thanks for the reply Michael..

If we have the unique ID of a layer then how do we retreive the layer back?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 12, 2013 Aug 12, 2013

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){}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 12, 2013 Aug 12, 2013
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines