-2

I found the following code and it works very well for most Photoshop files I have tried, but the file I want to use it with has 2 Smart Objects, one nested in the other. See attached images.

Is it possible to edit the code so it works with my particular file?

Here is the code:

Thanks for the help!

enter image description here

enter image description here

enter image description here

0

In your original question on Stack Overflow you never mentioned that two SOs are nested. In this case I suggest to open a SO as a document with

function editSmartObject()
{
    var desc = new ActionDescriptor();
    executeAction(sTID('placedLayerEditContents'), desc, DialogModes.NO);
}

If you're using only this particular file as an input your algorithm should be something like this I imagine in pseudocode:

var originaldocument = activeDocument,
    files = File.openDialog(...);

for file in files
    activeDocument = originaldocument; //selecting the original document
    editSmartObject() //opening SO for editing
    editSmartObject() //opening the second SO for editing
    // optionally remove a layer from previous iteration: activeDocument.activeLayer.remove()
    placeImage(file) //placing image to SO
    activeDocument.activeLayer.resize() //resize the placed layer if you need to
    activeDocument.close(SaveOptions.SAVECHANGES) //closing the second SO and saving changes
    activeDocument.close(SaveOptions.SAVECHANGES) //closing the first SO and saving changes
    saveJPG(); //save jpg with all the SO updated


function placeImage(imageFile)
{
    alert(imageFile);
    var desc554 = new ActionDescriptor();
    desc554.putPath(cTID('null'), imageFile);
    desc554.putEnumerated(cTID('FTcs'), cTID('QCSt'), cTID('Qcsa'));
    var desc555 = new ActionDescriptor();
    desc555.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 0.000000);
    desc555.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 0.000000);
    desc554.putObject(cTID('Ofst'), cTID('Ofst'), desc555);
    executeAction(cTID('Plc '), desc554, DialogModes.NO);
};

function editSmartObject()
{
    var desc = new ActionDescriptor();
    executeAction(sTID('placedLayerEditContents'), desc, DialogModes.NO);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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