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

Scripting layer comps of smart objects

Explorer ,
May 13, 2023 May 13, 2023

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?

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
Adobe
Community Expert ,
May 14, 2023 May 14, 2023

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

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 ,
May 14, 2023 May 14, 2023

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

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
Community Expert ,
May 14, 2023 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? 

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 ,
May 14, 2023 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 (:

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
Community Expert ,
May 14, 2023 May 14, 2023

As you say »Panel« this concerns UXP Scripting as opposed to ESTK Scripting? 

 

Could you give an example of a text that won’t process in »Find an Replace Text«? 

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 ,
May 14, 2023 May 14, 2023

im refering to estk scripting panel

like this:

panel sample.png

as for the text, im sorry i only have it in hebrew (since its originly the template language)

example lfor ong text i cant seem to put in "find and replace text":

"אי‭ ‬עמידה‭ ‬בפירעון‭ ‬ההלוואה‭/‬האשראי‭ ‬עלולה‭ ‬לגרור‭ ‬חיוב‭ ‬בריבית‭ ‬פיגורים‭ ‬והליכי‭ ‬הוצאה‭ ‬לפועל‭. ‬כפוף‭ ‬לתנאי‭ ‬החיתום‭ ‬ולאישור‭ ‬המלווה‭: ‬מקס‭ | ‬כפוף‭ ‬לתנאי‭ ‬ההטבה‭ ‬ולרישום‭ ‬להטבה‭ | ‬מלאי‭: ‬5000‭ ‬הטבות‭ | ‬צבירה‭ ‬בגובה‭ ‬1%‭ ‬ועד‭ ‬100‭ ‬₪‭ ‬החזר‭ | ‬התוקף‭ ‬לרישום‭ ‬ולצבירה‭ ‬בין‭ ‬התאריכים‭ ‬15.4.23-22.3.23‭ ‬או‭ ‬עד‭ ‬גמר‭ ‬המלאי"

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
Community Expert ,
May 14, 2023 May 14, 2023
quote

im refering to estk scripting panel

Do you mean »dialog« instead of »panel«? 

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 ,
May 15, 2023 May 15, 2023

im sorry in the webinar i took it was called a panel

i just want to make my own window like this one:panel sample.png

who will change the text according to the user input

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
Community Expert ,
May 20, 2023 May 20, 2023

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
};

 

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 ,
May 21, 2023 May 21, 2023

first thank you

im not sure i understood whats going on in this script

but ill try to run it and well see what happens (:

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
Community Expert ,
May 21, 2023 May 21, 2023

The script just collects an Array of the Smart Objects with an Array of the Layer Comps. 

 

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 ,
May 30, 2023 May 30, 2023

ok first thank you

i tried it and it did got my smart object but i dont understand how can i take this and create a list which i can choose from and change the layercomp inside the smart

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
Advisor ,
Mar 13, 2025 Mar 13, 2025

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?

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
Community Expert ,
Mar 14, 2025 Mar 14, 2025

Suppose a Smart Object has several Layer Comps and one wants to save copies with each Layer Comp applied in turn. 

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
Advisor ,
Mar 15, 2025 Mar 15, 2025

You mean from within the smart object or from the pad where smart object is in?

 

I have an extended version made myself for exporting layercomos from a main pad. Not with link pad actually. 

 

Quite interesting idea actually. Currently photoshop can save different layercomps per pad and also allow you to use with layercomps system in the main pad. 

 

Prior this function wasn't available, so I either relinked the same pad file and choose different layercomps in the smart object and then save a layercomps of that in the main pad

 

But since that new layercomps setting is available for best smart objects. I've run into issues where photoshop behaves weird, lags and other issues. If I remember well. I've turned it off and never used it again actually.

 

Other times when I need this for a say a mockup. I have a couple customized scripts for relink smart objects from a folder. Depending on the need, I have different versions of the script. One simply relinks, adjusts size to layermask and exports. The other actually relinks and downscales to original pad file. That way you can minimize cutoffs and other issues. Downside it's slower. It needs to open, relink, save, close, then export.  The first script, relinks,  scales, relinks.  Much faster

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
Advisor ,
Mar 15, 2025 Mar 15, 2025
LATEST

So the script at its current state is for information only. 

 

Perhaps for me, I could have a use for checking those bested layercomps in the smartobjects. 

 

That's pretty usefull for making another version of my script

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