1

Please help :)

In Photoshop CC under "File > Place Linked..." I can select a file to be placed as a linked layer (layer with a link icon over the layer thumbnail). I would like a Photoshop script to do this same process with a predetermined file path. To clarify, I do not want an embedded smart object. It must be linked to the file so if there are changes to the original linked file I can go to Menu: "Layer > Smart Objects > Update All Modified Content" and it will update the linked layer with the any new changes. The layer should look like this:

enter image description here

I was able to add a layer, convert it to a smart object, and replace it with a provided file. Only thing left is to have it be a linked layer rather than an embedded smart object.

If more info/screen shots are required please reach out, Any help is greatly appreciated!


var convertToSmartObject = function () {
    var idnewPlacedLayer = stringIDToTypeID('newPlacedLayer');
    executeAction(idnewPlacedLayer, undefined, DialogModes.NO);
};
var replaceSmartObjectContents = function (filePath, smartObj) {
    app.activeDocument.activeLayer = smartObj;
    var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
    var desc3 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    desc3.putPath(idnull, new File(filePath));
    var idPgNm = charIDToTypeID("PgNm");
    desc3.putInteger(idPgNm, 1);
    executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO);
};
var doc = app.activeDocument;

// Add a layer, this will now be the active layer
doc.artLayers.add();  

// Convert active layer to Smart Object
convertToSmartObject(); 

// replace a provided layer with a provided file path
replaceSmartObjectContents("~/Path/To/File.ai", doc.activeLayer);

2

1 Answer 1

2

If any one finds this, I've updated my script with the function linked by @SergeyKritskiy


function convertToSmartObject() {
    var idnewPlacedLayer = stringIDToTypeID('newPlacedLayer');
    executeAction(idnewPlacedLayer, undefined, DialogModes.NO);
} // end of convertToSmartObject()

function relinkSO(path) {
    var desc = new ActionDescriptor();
    desc.putPath(charIDToTypeID('null'), new File(path));
    executeAction(stringIDToTypeID('placedLayerRelinkToFile'), desc, DialogModes.NO);
} // end of relinkSO()

// Target current document
var doc = app.activeDocument;

// Add a layer, this will now be the active layer
doc.artLayers.add();  

// Convert active layer to Smart Object
convertToSmartObject(); 

// Relink active layer(smart object) with a provided file path
relinkSO("~/Path/To/File.ai");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.