Copy link to clipboard
Copied
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
No, they are the steps you need to take - with the exception of directly placing an external document as a Linked Smart Object.
Dave
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.ado
...
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
...
Copy link to clipboard
Copied
No, they are the steps you need to take - with the exception of directly placing an external document as a Linked Smart Object.
Dave
Copy link to clipboard
Copied
@Enid27216724xdpg – Let me see if this can be automated via scripting...
Copy link to clipboard
Copied
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()');
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html#Photoshop
Copy link to clipboard
Copied
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()");
Copy link to clipboard
Copied
This is magical! Saved me so much time, thank you!
I'm running Photoshop 2023, and I got an error saying that the functionality may not be available on this version:
"- Could not convert smart objects to linked because the file was not found.
Line: 58
-> executeAction(idplacedLayerConvertToLinked, desc346, DialogModes.NO);"
But I just deleted that line and it worked like a charm.
Thanks so much!
Copy link to clipboard
Copied
Ah, yes, there can be differences in AM code between versions, I mostly develop in 2021, but I don't always test in later versions.
I'm surprised it worked with that line deleted, my meagre understanding of AM code is that it is required. But if it works for you, it works!
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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: