Skip to main content
Known Participant
May 13, 2023
Question

Scripting layer comps of smart objects

  • May 13, 2023
  • 2 replies
  • 2781 views

Hello all (:

im new to scripting and I was wondering is there a way to have a script which gives a panel with drop-down menu to select layer comp inside a smart object I have on psd file?
I just have a lot of artbords in one psd which are just the same banner with different sizes and I want the ability to change a smart object on them to a specific layer comp, so I want the ability to have a panel with drop-down menu who collects all the layercomp inside that smart object and then change the smart object to what I choose. I'm just not sure that its even possible to do with scripting, since again I'm really new to scripting (but I'm using photoshop for about 20 years now).

can someone please help?

2 replies

c.pfaffenbichler
Braniac
May 14, 2023

Please post the screenshots @Stephen Marsh requested, including all pertinent Panels. 

 

I am not sure I understand the intended workflow. 

What advantage would an additional dialog with a dropdown list offer over the Properties Panel? 

Or do you want to change the Layer Comp an all instances of the Smart Object in the document? 

Known Participant
May 14, 2023

i uploaded a sample file

My actual file has 70 diffrent artboards sizes, and also is more complex than what i uploaded.

if youll see the file there is smart object which calls "max solid" and it has 13 layercomps inside of it. i want the ability to have a panel which inside of it you can replace all "max solid' to specific layercomp from selected drop down menu and also change all text and buttons colors across all artboards.

 all inside one panel which i will write, for now i found 2 problems:

1. i dont know if its possible to do the layercomp drop down menu

2. i found that the find and replace tect window wont support long text - when i try to trplace the legal text to long paragraph it wont let me paste the long paragraph into the text field.

 

hopefully now i explained myself better

and thank you very much for replying (:

schroef
Inspiring
March 13, 2025

Panels are persistent and do not »steal« focus, dialogs do take focus for as long as they are presented. 

So please clarify which behaviour you are after exactly. 

 

If you are fine with a ESTK-dialog this might provide a stepping stone; the function collects the Smart Object instances that have Layer Comps. 

With this it should be possible populate a dialog and then use the Layers’ IDs to apply a selected Layer Comp (via its ID) to all the instances of a specific Smart Object. 

// 2023, use it at your own risk;
if (app.documents.length > 0) {
var theThings = collectSmartObjectsWithLayerComps();
alert (theThings.length+" smart object instances with layer comps\n\n"+theThings.join("\n\n"));
};
////////////////////////////////////
////// collect smart objects, probably based on code by paul, mike or x //////
function collectSmartObjectsWithLayerComps () {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
if(layerDesc.hasKey(stringIDToTypeID('smartObject'))) {
    var soDesc = layerDesc.getObjectValue(stringIDToTypeID('smartObject'));
    var theFileRef = soDesc.getString(stringIDToTypeID('fileReference'));
    var theDocID = soDesc.getString(stringIDToTypeID('documentID'));
    var x = soDesc.getList(stringIDToTypeID("compsList"));
    var theCompsList = soDesc.getObjectValue(stringIDToTypeID("compsList"));
    if (theCompsList.count > 2) {
        var theCompsList = theCompsList.getList(stringIDToTypeID("compList"));
        var theSOComps = new Array;
        for (var n = 0; n < theCompsList.count; n++) {
        var thisOne = theCompsList.getObjectValue(n);
        var compName = thisOne.getString(stringIDToTypeID("name"));
        var compID = thisOne.getInteger(stringIDToTypeID("ID"));
        var theComment = thisOne.getString(stringIDToTypeID("comment"));
        theSOComps.push([compName, compID, theComment]);
        };
    theLayers.push([theName, theID, theFileRef, theDocID, theSOComps])
    };
//    theLayers.push([theName, theID, theFileRef, theDocID])
}
};
}
catch (e) {};
};
return theLayers
};

 


Note sure about the statement in the comment., But the script only prints a dialog with found info. What is the actually use case for this script?

Stephen Marsh
Braniac
May 14, 2023

@Lital2252941669o3 - Ideally a sample file would be provided, or at least a screenshot of the layers and comps panels to illustrate.

Known Participant
May 14, 2023

thank you for the replay - i uploaded the sample and explained myself better (hopefully)