• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
6

Save multilayer png/jpg smart objects as psb and automatically replace

Contributor ,
Nov 06, 2021 Nov 06, 2021

Copy link to clipboard

Copied

If I open a smart object, add a layer I want to preserve and hit save, I sometimes get this error:

 

"Can't save this document back to its original file format. Flatten layers and discard extra data as necessary then choose File > Save again. You can save the file using File > Save As, but the associated smart objects will not be updated."

 

Such a self-aware error message! The devs seem to know exactly what I want to do and are offering workarounds rather than just doing what I want. So my suggestion is: do what I want! When I press ctrl+s, save the multi-layer smart object as a psb instead of a png/jpg, then replace all instances of the existing smart object in the original document while maintaining their translations/styles/filters/etc.

 

Part of my confusion is that dragging a png or jpg into my file results in a png/jpg smart object, whereas if I ctrl+v paste it in then right click layer > Convert to Smart Object, I get a psb smart object. I do both interchangeably, and it's hard to know which format a smart object is before I crack it open and do a bunch of work on new layers I intend to preserve, only to hit this annoying error message which basically says "nah we know what you want but we're too lazy to do it". And it can be a LOT of work to go back and replace smart objects if they've been duplicated, scaled, styled, masked, filtered, and buried in groups.

Idea No status
TOPICS
Windows

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
15 Comments
Community Beginner ,
Oct 12, 2022 Oct 12, 2022

Copy link to clipboard

Copied

It also takes quite a bit more time when saving a smart object as a PNG file rather than a PSB, which adds annoying friction to the workflow. 

Votes

Translate

Translate

Report

Report
Explorer ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

One of my greatest pet peeves in PS. I just did all of this work warping a smart object to a mockup and when I go into the smart object to add layers I have to start all over. 

Votes

Translate

Translate

Report

Report
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

@marcg68495176 , you can »Replace Contents« and the Warp will be maintained, so your claim that you »have to start all over« seems incorrect. 

Votes

Translate

Translate

Report

Report
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

quote

And it can be a LOT of work to go back and replace smart objects if they've been duplicated, scaled, styled, masked, filtered, and buried in groups.

I appreciate the Request in principle but that statement seems peculiar. 

If you hit the alert then you apparently have opened an instance of a Smart Object that does not support Layers and it is likely to be active in the containing document, so what else do you have to look for? 

If you Replace its Contents all the other instances should update accordingly. 

Votes

Translate

Translate

Report

Report
Explorer ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

Here's the workflow. I drop in an image. It is a png. When drop it in it becomes a smart object. I make adjustments to that smart object. I double click on smart object to add another layer. I can't add another layer because the smart object is a flattened png, not a psb. Yes I can flatten it and work destructively, but thats not what I want to do. Instead I have to create a new multi-layer smart object and edit it all over again. Why not make every smart object a psb automatically? It's not a link so there's no reason for it to be confined to a flat png.

Votes

Translate

Translate

Report

Report
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

• Save the opened png with its Layers as a psd, psb or tif 

• close it 

• in the containing document Layer > Smart Objects > Replace Content and select that new file

 

So there is no need to »flatten it and work destructively«. (edited)

Votes

Translate

Translate

Report

Report
Explorer ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

I didn't know about this replace feature. Thank you for patiently
explaining it. I still don't understand why smart objects are not
automatically psbs and I have to do all of that rather than just edit and
save.

Votes

Translate

Translate

Report

Report
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

When one places a png or jpg that’s just that: A png or a jpg embedded in the layered file. 

Now I am not claiming that I haven’t done that myself, but those were my own mistakes and replacing the SOs was a (slight) inconvenience. 

But embedding a jpg for example can have (minor) filesize benefits. 

 

Automatically converting to psb would be undesirable in the case of placing ai, eps, svg and pdf because it would destroy the vector content – I am sure the Photoshop team would be able to exclude those formats in an automatic psb-conversion. 

Votes

Translate

Translate

Report

Report
Explorer ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

Understood thank you.

Votes

Translate

Translate

Report

Report
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

@marcg68495176 – I'll post a script for you later to automate the process!

Votes

Translate

Translate

Report

Report
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

The following script is intended to be run on an edited/open embedded smart object, where you have added layers to a flat file such as a JPEG, where the file will be automatically saved as a PSB and relinked.

 

/*
Create embedded PSB from Edited Smart Object layer.jsx
v1.0 - 15th February 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-ideas/save-multilayer-png-jpg-smart-objects-as-psb-and-automatically-replace/idi-p/12504206
* NOTE: Run this script on an open, layered embedded smart object to replace it as a PSB file (example, automatically convert an embedded JPEG to PSB)
*/

#target photoshop

// The open doc is a Mac embedded smart object
if (/^\/private\/var\/folders\//.test(app.activeDocument.path) === true && app.documents.length > 1) {
    embeddedToPSB();

// The open doc is a Win embedded smart object
} else if (/\/AppData\/Local\/Temp/.test(app.activeDocument.path) === true && app.documents.length > 1) {
    embeddedToPSB();

// The open doc isn't an embedded smart object
} else {
    alert("It doesn't appear that you are editing the contents of an embedded smart object!");
}


function embeddedToPSB() {
    // Create a temp folder with a "random" name
    var theTempDir = new Folder("~/Desktop/_theTempDir_51dcc44a-e898-47e8-bd34-6c1ecfe67faf");
    if (!theTempDir.exists) {
        theTempDir.create();

        // Save the open edited embedded image to a temp PSB file
        var thePSB = theTempDir + "/" + app.activeDocument.name.replace(/\.[^\.]+$/, '') + ".psb";

        function s2t(s) {
            return app.stringIDToTypeID(s);
        }
        var descriptor = new ActionDescriptor();
        var descriptor2 = new ActionDescriptor();
        descriptor2.putBoolean(s2t("maximizeCompatibility"), true);
        descriptor.putObject(s2t("as"), s2t("largeDocumentFormat"), descriptor2);
        descriptor.putPath(s2t("in"), new File(thePSB));
        descriptor.putBoolean(s2t("lowerCase"), true);
        descriptor.putEnumerated(s2t("saveStage"), s2t("saveStageType"), s2t("saveSucceeded"));
        executeAction(s2t("save"), descriptor, DialogModes.NO);
        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        // Replace the original embedded file with the temp PSB file
        function s2t(s) {
            return app.stringIDToTypeID(s);
        }
        var descriptor = new ActionDescriptor();
        descriptor.putPath(s2t("null"), new File(thePSB));
        executeAction(s2t("placedLayerReplaceContents"), descriptor, DialogModes.NO);

        // Remove the temp PSB before the temp folder can be removed
        thePSB = new File(thePSB);
        thePSB.remove();

        // Remove the empty temp folder
        theTempDir.remove();

        app.beep();

    } else {
        alert("Script cancelled as the temporary desktop folder already exists!");
    }
}

 

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

 

Votes

Translate

Translate

Report

Report
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

@Stephen_A_Marsh , there is a scenario where this Script could lead to unintended results. 

Suppose one oppened several of the affected SOs and edited them simultaneously. 

When using the Script the last selected SO in the containing document would be replaced, not necessarily the original SO. 

Screenshot 2024-02-15 at 08.16.12.pngScreenshot 2024-02-15 at 08.16.53.pngScreenshot 2024-02-15 at 08.20.32.pngScreenshot 2024-02-15 at 08.20.58.png

Votes

Translate

Translate

Report

Report
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

@c.pfaffenbichler 

 

Good point!

 

I only intended one open parent doc and one open smart object.

 

Both instances of:

 

app.documents.length > 1

 

Could be changed to:

 

app.documents.length == 2

 

However I wanted to have more flexibility for the number of open files, so I was only checking for more than 1 open doc.

 

Let the user beware I guess! Unless you have another idea?

Votes

Translate

Translate

Report

Report
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

As it is not a very likely scenario it does not seem very urgent anyway … 

 

I am not sure what the best approach would be, but maybe the easiest way would be having to start in the containing document with the SO selected and opening that via the Script etc. 

If it is already opened and edited that document should become the active one and one would be sure the SO is the active Layer in the next document down. 

 

Votes

Translate

Translate

Report

Report
Explorer ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

LATEST

Minor flaw aside, this script is extremely helpful. Thank you @Stephen_A_Marsh  for taking the time to create and share, and thank you @c.pfaffenbichler for all the info and testing. Much appreciated.

Votes

Translate

Translate

Report

Report