Copy link to clipboard
Copied
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.
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
...Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 ID | LayerComp ID |
---|---|
100 | 104 |
101 | 106 |
102 | 108 |
104 | 109 |
105 | 110 |
In above table, 104 is duplicated in Layer ID and LayerComp ID.
Is there any possibility to happen above duplication??
Copy link to clipboard
Copied
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 😉
Copy link to clipboard
Copied
Wow . Amazing explanation Jarda Bereza . Thanks a lot.
Copy link to clipboard
Copied
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?