Skip to main content
Known Participant
May 16, 2022
Question

To get the nested smart object layer names

  • May 16, 2022
  • 2 replies
  • 949 views

Hi All,

Is it possible to get the nested smart object layer names in the psd file using script?

This topic has been closed for replies.

2 replies

Stephen Marsh
Braniac
May 18, 2022
Oops, links removed, they lead to the same place as r-bin's!
Rocky@Author
Known Participant
May 23, 2022

Thanks r-bin, 
Now I can able to get all the nested smart object layer names from the json data. Now, I want to generate as report excel with artboard name(from the psd file) in one column along with respective nested smart objects layer names in another column, the 3rd to 5th column is final image size, resolution and name in the last smart object


Final Image(to get size & resolution):

 

Rocky@Author
Known Participant
May 18, 2022

Thanks r-bin!

 

I have found some information from the above thread. From the thread, AM code get the smart object layer name from the first level of smart object but in my psd files contains more than 5 nested of smart objects. Is it possible to get the nested smart object layer names?

Please find the attached psd file for reference, in the psd file contains with test1, test2, test3 nested smart object layers, my requirement is to get three smart object layer names & final image layer name

Braniac
May 18, 2022

It was a hint.

All information is in the json object.

You just need to extract it in the form you need.

For example

//////////////////////////////////////////////
function show_tree(json)
    {
    try {
        var s = "";

        show_layers(json.placed, json.layers, "");

        alert(s);

        function show_layers(placed, layers, level)
            {
            try {
                if (layers)
                    {
                    for (var i = 0; i < layers.length; i++)
                        {
                        var prefix = "Layer: ";
        
                        if (layers[i].layers) prefix = "Group: ";
                        if (layers[i].smartObject) prefix = "SmartObject: ";
        
                        s += level + prefix + layers[i].name + "\n";
                        
                        if (layers[i].smartObject) show_layers(placed, get_placed(placed, layers[i].smartObject.ID), "- " + level);
        
                        if (layers[i].layers) show_layers(placed, layers[i].layers, "- " + level);
                        }
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_placed(placed, placed_id)
            {
            try {
                if (placed)
                    {
                    for (var i = 0; i < placed.length; i++)
                        {
                        if (placed[i].placedID == placed_id) return placed[i].layers;
        
                        if (placed[i].placed) return get_placed(placed[i].placed, placed_id);
                        }
                    }
        
                return null;
                }            
            catch (e) { throw(e); }
            }
        }
    catch (e) { alert(e);  }
    }
        
//////////////////////////////////////////////
try {
    var r = new ActionReference();
    var d = new ActionDescriptor();
        
    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("json"));
    r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    d.putReference(stringIDToTypeID("null"), r);

    d.putBoolean(stringIDToTypeID("expandSmartObjects"), true);

    eval("var json="+executeAction(stringIDToTypeID("get"), d, DialogModes.NO).getString(stringIDToTypeID("json")));

    show_tree(json);

    alert(json.toSource());
    }
catch (e) { alert(e);  }