Skip to main content
namodayab94056659
Known Participant
February 27, 2018
Question

Is there way to get all layer names in current scene using Photoshop scripting?

  • February 27, 2018
  • 1 reply
  • 1948 views

I have found following code to get all layer names in the current scene using Photoshop scripting.

var getLayerNames = function() {

    var ref1 = new ActionReference();

    ref1.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));

    var count = executeActionGet(ref1).getInteger(charIDToTypeID('NmbL'));

    // get all layer names

    var layerNamesSet = [];

    for (var i = count; i >= 1; i--) {

      var ref2 = new ActionReference();

      ref2.putIndex(charIDToTypeID('Lyr '), i);

      var desc = executeActionGet(ref2);  // Access layer index #i

      var layerSection = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID('layerSection')));

     

      if (layerSection == 'layerSectionStart' || layerSection == 'layerSectionEnd') { // Group start and end

        continue;

      }

      var layerName = desc.getString(stringIDToTypeID("name"));

      layerNamesSet.push(layerName);

    }

    return layerNamesSet;

  }

In above function, list of layers names is returned. But in Photoshop scripting there is a direct way to get layer comps names as in below code.

var layerComps = app.activeDocument.layerComps;

I read a lot of references for Photoshop scripting. But I couldn't find direct way to get layer names as layer comps.

I want to know, is there any way to get layer names in directly?

This topic has been closed for replies.

1 reply

Kukurykus
Legend
February 27, 2018

Do you want to get array of layers from layers composition? If from current one it's the same what that above function does. Perhaps you want to extract them not by that function but from layers composition? From active one or any other on a list ?

namodayab94056659
Known Participant
February 28, 2018

I want to get all layer names from the current active document.

In above example, I want to get below names of the array.

  • Rectangle 1
  • Rectangle 2
  • Rectangle 3
  • Rectangle 4

I can do it using above mentioned function. I want to know is there any way to get it in direct method as Layer comps.