Skip to main content
Participant
May 26, 2022
Question

Nested smart objects Auto-update 2022

  • May 26, 2022
  • 5 replies
  • 2379 views

I'm creating tiles for a game engine.

I have a MASTER layout file into which I place linked external TILE psb files.

Each linked TILE file has inside it linked external TEXTURE psb files (so I can ensure all my base textures tile correctly)

 

As far as i can tell, if i change the TEXTURE tile, i have to manually open every TILE file and updated the modified content, then open the MASTER file and update all the modified content.

 

Is thewre any way for the MASTER file when opening to check the modified nested structure and update by itself? And if not could Adobe add such a function?

This topic has been closed for replies.

5 replies

Stephen Marsh
Community Expert
Community Expert
May 31, 2022

@Gravois 

 

Try this 1.1 version:

 

/*
Update linked layers inside linked layers v1-1.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/nested-smart-objects-auto-update-2022/m-p/12968009
Stephen Marsh, 31st May 2022, Version 1.1
*/

#target photoshop

var myDocument = app.activeDocument;
myDocument.suspendHistory("processAllSmartObjects", "processSOLayers(myDocument)");

function processSOLayers(docLayers) {
    // processSOLayers function courtesy of c.pfaffenbichler
    var restoreDialogMode = app.displayDialogs;
    app.displayDialogs = DialogModes.NO;
    // Loop over all the layers
    for (var i = docLayers.layers.length - 1; i >= 0; i--) {
        var theLayer = docLayers.layers[i];
        if (theLayer.typename === "ArtLayer") {
            var theVisibility = theLayer.visible;
            myDocument.activeLayer = theLayer;

            // Linked SO conditional check courtesy of r-bin
            var r = new ActionReference();
            r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));
            r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
            var d = executeActionGet(r);
            if (d.hasKey(stringIDToTypeID("smartObject"))) {
                d = d.getObjectValue(stringIDToTypeID("smartObject"));
                if (d.hasKey(stringIDToTypeID("link"))) {

                    // Edit the linked smart object layer
                    app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
                    // Update all modified content
                    app.runMenuItem(stringIDToTypeID('placedLayerUpdateAllModified'));
                    // Close and save
                    app.activeDocument.close(SaveOptions.SAVECHANGES);

                }
            }

            // Reset visibility; 
            theLayer.visible = theVisibility;

            // Run on the contents of layerSets (implied, not explicitly defined)
        } else {
            processSOLayers(theLayer);
        }
    }

    app.displayDialogs = restoreDialogMode;

    return;
}

 

 

Stephen Marsh
Community Expert
Community Expert
May 27, 2022

@Gravois – The following script will update linked files within linked files, so only 2 levels deep. I have tested it and I believe that it meets your criteria. Let me know how it goes for you...

 

/*
Update linked layers inside linked layers.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/nested-smart-objects-auto-update-2022/m-p/12968009
Stephen Marsh, 28th May 2022, Version 1.0
With special thanks to Christoph Pfaffenbichler for the recursive SO processing framework:
https://feedback.photoshop.com/photoshop_family/topics/rasterize_all_smart_objects_in_a_psd_file_to_shrink_down_its_size
*/

#target photoshop

var myDocument = app.activeDocument;
myDocument.suspendHistory("processAllSmartObjects", "processSOLayers(myDocument)");

processSOLayers(theLayer);

function processSOLayers(docLayers) {

    var restoreDialogMode = app.displayDialogs;
    app.displayDialogs = DialogModes.NO;

    // Loop over all the layers
    for (var i = docLayers.layers.length - 1; i >= 0; i--) {
        var theLayer = docLayers.layers[i];

        // Only run on smart object layers
        if (theLayer.typename === "ArtLayer" && theLayer.kind === LayerKind.SMARTOBJECT) {
                var theVisibility = theLayer.visible;
                myDocument.activeLayer = theLayer;

                // Edit the linked smart object layer
                app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
                // Update all modified content
                app.runMenuItem(stringIDToTypeID('placedLayerUpdateAllModified'));
                // Close and save
                app.activeDocument.close(SaveOptions.SAVECHANGES);

                // Reset visibility; 
                theLayer.visible = theVisibility;

        // Run on the contents of layerSets (implied, not explicitly defined)
        } else {
            processSOLayers(theLayer);
        }
    }
    
    app.displayDialogs = restoreDialogMode;
    
    return;
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save the text file as .txt
  5. Rename the file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run:

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

davescm
Community Expert
Community Expert
May 28, 2022

@Stephen Marsh  Thanks Stephen 🙂

Dave

Mike_Gondek10189183
Community Expert
Community Expert
May 27, 2022

Yes that is how it works on multiple files. Look into Layer comps, they are a great way to have one master file to create multiple files in a series. 

 

With layer comps use file >> Export >> Layer Comps To files to generate your files.

 

Another way taht shdou work is to drag a layer to your library. Later after adding the library item to your files or Russian doll, edit the library item by double clicking on the item in the library.

GravoisAuthor
Participant
May 30, 2022

Thanks Mike, i did get the script method working, but the library method sounds promising as well. One reason we avoid photoshop libraries (in our company) is that we use an SVN to commit and version projects so have always tried to avoid being tied to a users library.. maybe there's a way to keep the project library as a local foldered version?

Stephen Marsh
Community Expert
Community Expert
May 27, 2022

If I am understanding the "Russian Doll" issue, then yes, I believe that a script can handle this... Even better, I believe that it is within my capabilities!

davescm
Community Expert
Community Expert
May 26, 2022

You are correct in that it does work that way.

 

I wonder though if a script could be written to open each and update? I am no expert in scripting though, so have tagged a couple of folk who are:   @jazz-y  @Stephen Marsh 

 

Dave