Skip to main content
Participant
November 19, 2022
Answered

Converting to *Linked* Smart Object?

  • November 19, 2022
  • 2 replies
  • 2242 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
Community Expert
November 19, 2022

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

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
November 19, 2022

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()");

 

Stephen Marsh
Community Expert
Community Expert
December 21, 2022

Ah I see, I was looking for a way to convert multiple layers into individual smart objects. I think the original poster was looking for the answer to something else. That's probably why the script still worked for me!


quote

Ah I see, I was looking for a way to convert multiple layers into individual smart objects. I think the original poster was looking for the answer to something else. That's probably why the script still worked for me!


By @TravisProuty

 

@Enid27216724xdpg  wanted to automatically convert "normal" layers to linked SO layers, without having to manually perform the required steps of first converting to embedded, then converting to linked and saving the linked file. The script that I posted simply automated the steps as they are required and can't be avoided, however, automation can make that task much easier.

 

If you wish to simply select multiple layers and convert each to a separate embedded SO, then the following scripts will do that for you:

 

davescm
Community Expert
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