Updating SmartObject Layer Comps according to their names
Layers structure:

Each of these Smart Objects has it's own LayerComps with names similar to the layer name:

I need to switch on each of the Smart Objects in the LayerSet "Element" one by one and apply the specified LayerComp at the same time. E.g. "Element Red" got "Red" LayerComp applied, "Element Yellow" - "Yellow", etc.
What I have for now.
I've modified a bit Michael L Halecode posted here to switch layers one by one. It's all looks like that:
var DBG = 1;
var id = getSelectedLayerID();
var name = getLayerNameByID(id);
var variations = ["Red", "Yellow", "Green", "Blue"];
if(DBG) {alert("id="+id+"; name="+name); };
for( i=0; i<variations.length; i++ ) {
layerName = name+" "+variations;
showSetByOne( layerName, name );
if(DBG) {alert(layerName)};
}
function showSetByOne( layerName, groupName ){
var setFolder = app.activeDocument.activeLayer;
if (setFolder.typename == 'LayerSet' && setFolder.name == groupName ) {
for( var setIndex = 0; setIndex<setFolder.layers.length; setIndex++) {
if(setFolder.layers[setIndex].name == layerName){
setFolder.layers[setIndex].visible = true;
switchPlacedLayerComp(setFolder.layers[setIndex].id, 1402355601); //exact ID of one of the LayerComps got from ScriptListener
}else{
setFolder.layers[setIndex].visible = false;
}
}
}
}
function switchPlacedLayerComp(id, compID) {
// (ref = new ActionReference()).putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));
(ref = new ActionReference()).putIdentifier( sTT("layer"), id );
// (ref = new ActionReference()).putIndex( sTT("layer"), id );
(desc = new ActionDescriptor()).putReference( sTT("null"), ref );
// alert("Inside Func: "+id);
desc.putInteger( sTT("compID"), compID );
// desc.putString( sTT("comp"), "Red" );
executeAction( sTT("setPlacedLayerComp"), desc, DialogModes.NO );
}
But I can not find any way to process the Smart Objects Layer Comps applying. If to select the exact SO layer and use the exact "compID" ( 1402355601) that was got from Script Listener then LayerComp applies to. But I have only LayerComps names but not IDs. And I could not apply LayerComp to SmartObject without selecting it. Neither by SmarObject id nor by name.
Kukurykus it seems I could not solve this puzzle without your help ![]()
Thanks to all for help in advance! ![]()
