Skip to main content
New Participant
November 19, 2022
Answered

Converting to *Linked* Smart Object?

  • November 19, 2022
  • 2 replies
  • 2193 views

Hello all,

 

I'm looking for a way to convert layers to a *linked* smart object without having to, first, Convert to Smart Object, and secondly, Convert to Linked... Does anyone know if this is a possibility?

 

Thank you for any help 🙂

Enid

This topic has been closed for replies.
Correct answer Stephen Marsh

This version will create linked smart object layers for all selected "normal" top-level raster layers and layer groups. The linked SO PSB files will be automatically saved to the same path as the parent file (this could be changed to a sub-folder if more convenient for file management). A single undo history step is provided.

 

/*
Selected Layers to Linked Smart Objects.jsx
v1.0, 20th November 2022, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/converting-to-linked-smart-object/td-p/13357539
*/

#target photoshop

function main() {

    ///// Process selected layers - from jazz-y /////
    var s2t = stringIDToTypeID;
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
    r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
    var lrs = executeActionGet(r).getList(p),
        sel = new ActionReference();
    for (var i = 0; i < lrs.count; i++) {
        sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
        (r = new ActionReference()).putIdentifier(s2t('layer'), p);
        (d = new ActionDescriptor()).putReference(s2t("target"), r);
        executeAction(s2t('select'), d, DialogModes.NO);

        /////

        // Conditional check for normal or smart object layers, ignoring other layer kinds such as adjustment layers
        if (activeDocument.activeLayer.kind == LayerKind.NORMAL || activeDocument.activeLayer.kind == LayerKind.SMARTOBJECT) {
            newPlacedLayer();
            placedLayerConvertToLinked();
        }


        ///// Functions /////

        // Convert the active layer to an embedded smart object
        function newPlacedLayer() {
            var s2t = function (s) {
                return app.stringIDToTypeID(s);
            };
            executeAction(s2t("newPlacedLayer"), undefined, DialogModes.NO);
        }

        // Convert the active embedded smart object to a linked smart object
        function placedLayerConvertToLinked() {
            var savePath = activeDocument.path;
            // RegEx remove illegal/invalid filename characters from document name
            var layerName = activeDocument.activeLayer.name.replace(/[:\/\\*\?\"\<\>\|\\\r\\\n.]/g, ""); // "/\:*?"<>|\r\n" -> "-";;
            var idplacedLayerConvertToLinked = stringIDToTypeID("placedLayerConvertToLinked");
            var desc346 = new ActionDescriptor();
            var idnull = stringIDToTypeID("null");
            var ref49 = new ActionReference();
            var idlayer = stringIDToTypeID("layer");
            var idordinal = stringIDToTypeID("ordinal");
            var idtargetEnum = stringIDToTypeID("targetEnum");
            ref49.putEnumerated(idlayer, idordinal, idtargetEnum);
            desc346.putReference(idnull, ref49);
            var idusing = stringIDToTypeID("using");
            desc346.putPath(idusing, new File(savePath + "/" + layerName + ".psb"));
            executeAction(idplacedLayerConvertToLinked, desc346, DialogModes.NO);
        }


    }
}
app.activeDocument.suspendHistory("Selected Layers to Linked Smart Objects", "main()");

 

2 replies

Stephen Marsh
Community Expert
November 19, 2022

@Enid27216724xdpg – Let me see if this can be automated via scripting...

Stephen Marsh
Community Expert
November 19, 2022

The following script will create linked smart object layers for all "normal" top-level raster layers and layer groups. The linked SO PSB files will be automatically saved to the same path as the parent file (this could be changed to a sub-folder if more convenient for file management). A single undo history step is provided. I'll look into making a version for selected layers only.

 

/*
All Top-level Layers to Linked Smart Objects.jsx
v1.0, 20th November 2022, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/converting-to-linked-smart-object/td-p/13357539
Based on:
https://community.adobe.com/t5/photoshop/smart-objects-in-separate-layers/td-p/11137197
*/

#target photoshop

function main() {

    try {
        activeDocument.path;
        processAllLayersAndSets(app.activeDocument);
    } catch (error) {
        alert("An image must be open and saved before running this script!");
    }

    function processAllLayersAndSets(obj) {
        // Process all layers and layer sets
        // Change the following 2 entries of "obj.layers" to "obj.artLayers" to exclude layer sets
            for (var al = obj.layers.length - 1; 0 <= al; al--) {
                app.activeDocument.activeLayer = obj.layers[al];
                // Conditional check for normal or smart object layers, ignoring other layer kinds such as adjustment layers
                if (obj.layers[al].kind == LayerKind.NORMAL || obj.layers[al].kind == LayerKind.SMARTOBJECT) {
                newPlacedLayer();
                placedLayerConvertToLinked();
            }

            // Process Layer Set Layers 
            for (var ls = obj.layerSets.length - 1; 0 <= ls; ls--) {
                processAllLayersAndSets(obj.layerSets[ls]);
                newPlacedLayer();
                placedLayerConvertToLinked();
            }
        }
    }


    ///// Functions /////

    // Convert the active layer to an embedded smart object
        function newPlacedLayer() {
            var s2t = function (s) {
                return app.stringIDToTypeID(s);
            };
            executeAction(s2t("newPlacedLayer"), undefined, DialogModes.NO);
        }

    // Convert the active embedded smart object to a linked smart object
    function placedLayerConvertToLinked() {
        var savePath = activeDocument.path;
        // RegEx remove illegal/invalid filename characters from document name
        var layerName = activeDocument.activeLayer.name.replace(/[:\/\\*\?\"\<\>\|\\\r\\\n.]/g, ""); // "/\:*?"<>|\r\n" -> "-";;
        var idplacedLayerConvertToLinked = stringIDToTypeID("placedLayerConvertToLinked");
        var desc346 = new ActionDescriptor();
        var idnull = stringIDToTypeID("null");
        var ref49 = new ActionReference();
        var idlayer = stringIDToTypeID("layer");
        var idordinal = stringIDToTypeID("ordinal");
        var idtargetEnum = stringIDToTypeID("targetEnum");
        ref49.putEnumerated(idlayer, idordinal, idtargetEnum);
        desc346.putReference(idnull, ref49);
        var idusing = stringIDToTypeID("using");
        desc346.putPath(idusing, new File(savePath + "/" + layerName + ".psb"));
        executeAction(idplacedLayerConvertToLinked, desc346, DialogModes.NO);
    }

}

activeDocument.suspendHistory('All Top-level Layers to Linked Smart Objects', 'main()');

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save the text file as .txt
  5. Rename the file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below):

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html#Photoshop

davescm
Community Expert
November 19, 2022

No, they are the steps you need to take - with the exception of directly placing an external document as a Linked Smart Object.

 

Dave