4 Replies Latest reply on Aug 12, 2013 7:23 AM by _VG

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

    _VG Level 1

      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.

        • 1. Re: How to set and get key/ID to a particular layer.
          Michael L Hale Level 5

          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.

          1 person found this helpful
          • 2. Re: How to set and get key/ID to a particular layer.
            _VG Level 1

            Thanks for the reply Michael..

             

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

            • 3. Re: How to set and get key/ID to a particular layer.
              Michael L Hale Level 5

              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){}
              }
              
              1 person found this helpful
              • 4. Re: How to set and get key/ID to a particular layer.
                _VG Level 1

                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.