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

Get layer comps ID using Photoshop scrpting

Explorer ,
Mar 07, 2018 Mar 07, 2018

I have found following script code to get all layer comps name,

var layerComps = app.activeDocument.layerComps;

But I want to get layerComps names with their IDs.

Is there any script to get layer comps names with their IDs?

Sample example for getting Layer names with their IDs:

var getLayerNamesWithID = function() {

    var ref1 = new ActionReference();

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

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

    // get all layer names with their IDs

    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"));

      var layerId = desc.getInteger(charIDToTypeID("LyrI"));

      layerNamesSet.push({

        name: layerName,

        id: layerId

      });

    }

    return layerNamesSet;

}

I want to get LayerComps names with their IDs same as above. Please help me.

TOPICS
Actions and scripting
2.6K
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

correct answers 1 Correct answer

People's Champ , Mar 07, 2018 Mar 07, 2018

If you have CC2018 then the easiest way is here:

var r = new ActionReference();   

r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("json"));   

r.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

eval("var comps = " + executeActionGet(r).getString(stringIDToTypeID("json")) + ".comps");

alert(comps.length)

alert(comps.toSource())

for (var i = 0; i < comps.length; i++)

    alert(comps.id + " " + comps.name)

If you have CS6, then you need to go the other way (ha

...
Translate
Adobe
LEGEND ,
Mar 07, 2018 Mar 07, 2018

I worked hard on this forum last months, but currently I'm time limited, so sorry I couldn't help in there Is there way to get all layer names in current scene using Photoshop scripting? , but I believe r-bin​ should handle it with no problem

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
People's Champ ,
Mar 07, 2018 Mar 07, 2018

If you have CC2018 then the easiest way is here:

var r = new ActionReference();   

r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("json"));   

r.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

eval("var comps = " + executeActionGet(r).getString(stringIDToTypeID("json")) + ".comps");

alert(comps.length)

alert(comps.toSource())

for (var i = 0; i < comps.length; i++)

    alert(comps.id + " " + comps.name)

If you have CS6, then you need to go the other way (harder)

If you need, then tell me.

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
Explorer ,
Mar 07, 2018 Mar 07, 2018

Thank you very much r-bin . It is working. I want to work with Photoshop CC 2014, 2015 and 2017. I have executed with them. It is working without any issues.

Also, I want to know that can layerComp IDs and layer IDs mutually duplicated (same ID for both layerComp and layer)?

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
Enthusiast ,
Mar 07, 2018 Mar 07, 2018

ID should be unique. Anyway I have seen some panel with same ID for multiple items. Not sure if it was paths o something else.

Layer ID is always unique.

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
Explorer ,
Mar 07, 2018 Mar 07, 2018

Thank you Jarda Bereza for quick response. According to my understanding, Layer IDs and LayerComp IDs always unique. But I want to know is there any duplication of Layer IDs and LayerComp IDs.

Example (Please note that these ids on example are not actual ids of photoshop. This is just an example to explain the question,):

Layer IDLayerComp ID
100104
101106
102108
104109
105110

In above table, 104 is duplicated in Layer ID and LayerComp ID.

Is there any possibility to happen above duplication??

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
Enthusiast ,
Mar 08, 2018 Mar 08, 2018

Layer ID usually starts from 1 for new document and always continues up.

Meanwhile compIDs are usually big numbers which seems to be random, but it could be possibly pointers in memory.

Limit of layers in file is 8000. It is unlikely that you create and remove 100 000 000 layers in Photoshop.

Smart object comps uses -1 for "Don't apply layer comp" and 0 for last document state. Layer IDs starts from 1

So it is very unlikely but possible. Just do it right and don't write dirty code 😉

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
Explorer ,
Mar 08, 2018 Mar 08, 2018

Wow . Amazing explanation Jarda Bereza . Thanks a lot.

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
People's Champ ,
Mar 08, 2018 Mar 08, 2018
LATEST

I do not know the answer to this question. I will try to find out

But I know that the Layer ID and Channel ID can not match. But the Path ID and the Layer ID can match.

P.S. And why do you need this?

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