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

Artlayers unique ID... (CS5)

Guest
Mar 15, 2011 Mar 15, 2011

Copy link to clipboard

Copied

Hi,

I want export layers names with unique ids to external file.I search a lot in documentation and also on Internet and I didnt find anything about unique ids of layers in photoshop. Each created artlayer should have own unique id, right? So, how to get that uid?

Greeds.

TOPICS
Actions and scripting

Views

4.0K

Translate

Translate

Report

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

correct answers 1 Correct answer

Guru , Mar 15, 2011 Mar 15, 2011

Here is how to get the layer's ID. But as Paul said the ID is only unique to the document. And the background layer always returns 0 and it's id is not unique.

function getActiveLayerId() {
    var ref = new ActionReference();
    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "LyrI" ));
    ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    return executeActionGet(ref).getInteger( stringIDToTypeID( "layerID" ) );
}

Note I used both the string

...

Votes

Translate

Translate
Adobe
Valorous Hero ,
Mar 15, 2011 Mar 15, 2011

Copy link to clipboard

Copied

Using Mike's function will get you the layer ID's but these are only unique to that one document.


var LayerArray =[];
LayerArray = getSelectedLayersIdx();
alert(LayerArray.toString());

function getSelectedLayersIdx(){
     var selectedLayers = new Array;
     var ref = new ActionReference();
     ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
     var desc = executeActionGet(ref);
     if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
          desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
          var c = desc.count
          var selectedLayers = new Array();
          for(var i=0;i<c;i++){
               selectedLayers.push(  desc.getReference( i ).getIndex());
          }
     }else{
          var ref = new ActionReference();
          ref.putProperty( charIDToTypeID('Prpr') , charIDToTypeID( 'ItmI' ));
          ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
          selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' )));
     }
     return selectedLayers;
}

Votes

Translate

Translate

Report

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
Guest
Mar 15, 2011 Mar 15, 2011

Copy link to clipboard

Copied

Thanks. That is nice snippet. But You can specify which function / line is responsible for UID?

That codes:

'Dcmn', 'ItmI', 'Lyr ', 'Prpr', etc.

Tells me tottaly nothing : ( Where I can find reference to them?

Votes

Translate

Translate

Report

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
Valorous Hero ,
Mar 15, 2011 Mar 15, 2011

Copy link to clipboard

Copied

More than one of those. Here is some of Mike code to get the active layers index.

Using the numeric makes the code faster as no conversion is required.

It is not possible to use one line of code to get the index.


function getActiveLayerIndex() {
     var ref = new ActionReference();
     ref.putProperty( 1349677170 , 1232366921 );
     ref.putEnumerated( 1283027488, 1332896878, 1416783732 );
     var res = executeActionGet(ref).getInteger( 1232366921 ) /* This is the index */
                                                       - Number( hasBackground() );
     return res;  
}

function hasBackground(){
    var res = undefined;
    try{
        var ref = new ActionReference();
        ref.putProperty( 1349677170 , 1315774496);
        ref.putIndex( 1283027488, 0 );
        executeActionGet(ref).getString(1315774496 );;
        res = true;
    }catch(e){ res = false}
    return res;
}

Votes

Translate

Translate

Report

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
Guest
Mar 15, 2011 Mar 15, 2011

Copy link to clipboard

Copied

I am not tested this yet but this code get 'index' property from layers. Index is this same as unique id? Layer index isn't a position on layer list? So when I move layer - index will be changed... Please correct me if I'm wrong...

Unique ID is always this same for each layer - I can change name, position on artboard, position in layer list and I still will have this same UID.

Votes

Translate

Translate

Report

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 ,
Mar 15, 2011 Mar 15, 2011

Copy link to clipboard

Copied

Here is how to get the layer's ID. But as Paul said the ID is only unique to the document. And the background layer always returns 0 and it's id is not unique.

function getActiveLayerId() {
    var ref = new ActionReference();
    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "LyrI" ));
    ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    return executeActionGet(ref).getInteger( stringIDToTypeID( "layerID" ) );
}

Note I used both the stringID and charID for the layerID key. You can find some information about charID and stringID in the Photoshop SDK. You can find the most up to date list I know of in Xbytor's xtools.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 19, 2015 Feb 19, 2015

Copy link to clipboard

Copied

Do we really need to activate layer for this?

I noted a considerable performance hit due to activating the layer.

Suppose, I am traversing layers using a for loop.

Then I have a layer object.

How do I directly get layer ID from this layer object?

    for(var layerIndex=0; layerIndex < layerNodes.length; layerIndex++)

    {

            var currLayer = layerNodes[layerIndex];

             try{

                   // get layerID by "currLayer"  ?

             }catch(e){

             }

    }

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 20, 2015 Feb 20, 2015

Copy link to clipboard

Copied

var ref = new ActionReference();

ref.putIndex( charIDToTypeID( "Lyr " ), layerIndex);

var layerDesc = executeActionGet(ref);

var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));

Votes

Translate

Translate

Report

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 Employee ,
Feb 20, 2015 Feb 20, 2015

Copy link to clipboard

Copied

You should always ask for one key as well. Asking for all the keys is very slow if you have text on the layer for example. I would add this line ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID('layerID') );

Something like this:

var ref = new ActionReference();

ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID('layerID') );

ref.putIndex( charIDToTypeID( "Lyr " ), layerIndex);

var layerDesc = executeActionGet(ref);

var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 22, 2015 Feb 22, 2015

Copy link to clipboard

Copied

LATEST

Good point.

Votes

Translate

Translate

Report

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 Employee ,
Apr 06, 2011 Apr 06, 2011

Copy link to clipboard

Copied

PITerminology.h in the Photoshop SDK has a bit more descriptive

constants but it is not much help and they are sometimes inconsistent.

Votes

Translate

Translate

Report

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