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

Can I loop an action in Photoshop ?

New Here ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

I have over 50 images stacked as 50 layers in a document and want to convert each layer into a smart object. What is the best way to do it? I thought of creating an action to covert to smart object and run it over 50 layers. But I could't find a way to loop that action. Any help would be highly appreciated. 

Thank you. 

(Ps: I saw a simier question asked by someone else and the answer was a script to run. I have no idea about scripts or coding. So couldn't really understand the reply.)

TOPICS
Actions and scripting

Views

5.6K

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
Adobe
Community Expert ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

Hi,

You can loop through all the layers using javscript and call your actions using method app.doAction

 

 

var doc = app.activeDocument;
for (var i = 0; i < doc.layers.length; i++) {
    doc.activeLayer = doc.layers[i];
    app.doAction("Action 1","Set 1");
}

 

 

app.doAction will take two parameters, first is Name of the action(here "Action 1") and second is Set Name (here "Set 1") in which exists. You can change both according to your actions defined in the photoshop.

 

Let us know if this works for you.

 

 

Best regards

Votes

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
Community Expert ,
Jun 06, 2020 Jun 06, 2020

Copy link to clipboard

Copied

That script would just process top level layers to process all layers you need to use recursion.

 

 

var allLayers = "";
processArtLayers(activeDocument) 
alert(allLayers, "Layers");
function processArtLayers(obj) {  
    for( var i = obj.artLayers.length-1; 0 <= i; i--) {/* alert(obj.artLayers[i]); */processLayers(obj.artLayers[i])}  
    for( var i = obj.layerSets.length-1; 0 <= i; i--) {/* alert(obj.layerSets[i]); */processArtLayers(obj.layerSets[i])} // Process Layer Set Layers  
} 
function processLayers(layer) { 
	allLayers = allLayers + "ID " + layer.id + ", " + layer.name + ", " + layer.kind + "\n";
	switch (layer.kind){
	default : break; // none process layer types catch all
	}
} 
JJMack

Votes

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
Community Expert ,
Jun 06, 2020 Jun 06, 2020

Copy link to clipboard

Copied

That's 100% correct. The above snippet will only convert the top most layers.

Here is the new version, that will convert all layers inside the groups into smart objects 🙂

 

 

#target photoshop

var doc = app.activeDocument;

function covertLayersToSmartObjects(_layers){
    for (var i = 0; i < _layers.length; i++) {
        if(_layers[i].layers && _layers[i].layers.length)
            covertLayersToSmartObjects(_layers[i].layers)
        else{
            doc.activeLayer = _layers[i];
            app.doAction("Action 1","Set 1");
        }
     }
}

covertLayersToSmartObjects(doc.layers);

 

Best regards

Votes

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
Community Expert ,
Jun 06, 2020 Jun 06, 2020

Copy link to clipboard

Copied

IMO its a strange request without knowing exactly what their stack of image look like.  If any are placed images they are smart object layers to begin with.  You can convert smart object layer to smart object layers but the object is no longer an images file its a smart object layer. I also do not think you would want to convert any adjustment layers to a smart object layer they would most likely not adjust anything. Converting a text layer to a smart object layer makes it necessary for you to open the object to edit the text. That script can play havoc on a document. 

JJMack

Votes

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
New Here ,
Jun 09, 2020 Jun 09, 2020

Copy link to clipboard

Copied

Well, I didn't detail the purpose in my question.  Well, here's the situaion.  (TLDR + bad English alert is ON) 

 

I do product photography for my own Optical business and want to put each image on perfect white background to display it online. I work on my own , have many products and it's a hard to work on one image at a time. So this is my workflow:

  • I take photos on white background, import them on LR and do basic edits, and then open the images ( 20-50 images at once) in photoshop as layers.
  • To get the background pure white, I put a solid color (fffffff white) adjustment layer as the last layer down. 
  • Then I work on product layers one by one ( as in the attached screenshot ). Select the imge surroundings>delete the extra outer part of the image > work on the remaining image area and get the whites white using levels( for this levels, I don't use adjustment layers, but just on the image itself).
  • Here comes the tricky part. To Save the image with pure white background, I need a white solid color background beneath it. ( Please see the layer pannel of second screenshot to see how the actual image layer looks like). I find it hard to save one image, then work on the second image and save it, then third..  
  • So what I do is, I finsh all my layers and duplicate the solid color adjustment layer to put one soild color layer beneath each image layer .
  • Now I put each image and it's solid color pair to a group. I do the same to all the pairs. ( third screenshot)
  • This is when I need to convert each group into smart object. Because, now I use the Export/ Layers to files menu option to export all the images at once. But the very 'wise' PS doesn't consider these groups as layers now. It just exports the contents of the group, and not the group itself. So I need to convert each group into an SO and then PS could export it. 

 

I would also appreciate, if there's better workflow you could suggest. But only if there was some option to convert all the layers/groups to SO, it would've been so much easier for me. 

 

Ps: I tried the script by Charu Rajput. ( Thank you Stephen for your detailed note on how to use the scripts). I pasted it on my TextEdit and saved it as jsx in the script folder. But the file is grayed out. Tried rebooting PS and Mac but no use. Any suggestions? 

 

Thanks a lot for your patience and time. 

 

 

 

  • Screen Shot 2020-06-10 at 12.20.25 AM.png

Screen Shot 2020-06-10 at 12.30.59 AM.png

Screen Shot 2020-06-10 at 12.40.24 AM.png

Votes

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
Community Expert ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

I wrote such a script to create a separate SO from all top level layers/sets here, so no need for an action:

 

https://community.adobe.com/t5/photoshop/smart-objects-in-separate-layers/m-p/11137197?page=1#M33176...

 

// convert all top level layers and layer sets to smart objects.jsx

function main() {

    if (!documents.length) {
        alert('There are no documents open!');
    } else {
        processAllLayersAndSets(app.activeDocument);
    }

    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];

            newPlacedLayer();

        }

        // Process Layer Set Layers 
        for (var ls = obj.layerSets.length - 1; 0 <= ls; ls--) {
            processAllLayersAndSets(obj.layerSets[ls]);

            newPlacedLayer();

        }
    }

    // Convert to smart object (Cleaned AM code)
    function newPlacedLayer() {
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };
        executeAction(s2t("newPlacedLayer"), undefined, DialogModes.NO);
    }
}

activeDocument.suspendHistory('Smart Objects from Layers & Sets', 'main()');

 

That being said, the great thing about a script that plays an action is that you can record an action to do what you want without having to rely on somebody to write you a specific script.

Votes

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
Community Expert ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

(Ps: I saw a simier question asked by someone else and the answer was a script to run. I have no idea about scripts or coding. So couldn't really understand the reply.)

 

I created the following guide to help users such as yourself use scripts:

 

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

Votes

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
New Here ,
Jun 09, 2020 Jun 09, 2020

Copy link to clipboard

Copied

Thanks a lot . I have wrote a reply in detail to JJMac in this thread. I would love to have suggestions from you too. 

Votes

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
Community Beginner ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

Here is a script, put this in a file RunActionX-Times.jsx(change the extension from .txt to .jsx) and copy to your Adobe Photoshop>Presets>Scripts folder on windows.

In Photoshop, your new script should appear under File>scripts. Just type in the number of times you want an action to run and VIOLA! Works like a charm!

 

Credit to jcombs

Link to original discussion

https://www.ozzu.com/questions/455621/photoshop-play-an-action-repeatedly#post-607170

Votes

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
Participant ,
Nov 02, 2022 Nov 02, 2022

Copy link to clipboard

Copied

Hi guys, I am in need of something similar but I added a Save step to my action. But it seems that as the action is looped in the script, the save is always with the same name, overwritting each file instead of saving each layer to a separate file 😞

Votes

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
Community Expert ,
Nov 02, 2022 Nov 02, 2022

Copy link to clipboard

Copied

quote

Hi guys, I am in need of something similar but I added a Save step to my action. But it seems that as the action is looped in the script, the save is always with the same name, overwritting each file instead of saving each layer to a separate file 😞


By @ShynnSup

 

When recording the save step in the Action, don't change/touch the filename, just navigate to the location where you wish to save. The recorded Action step will then only include the save path, not the save path + file name.

 

Votes

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
Participant ,
Nov 02, 2022 Nov 02, 2022

Copy link to clipboard

Copied

Ah this actually promts me to save each time, and I need like 200 layers.

 

But you gave me another idea. I can just run the script which loops the action without saving. And then use Export>Layer to Files 😄

Votes

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
Community Expert ,
Nov 02, 2022 Nov 02, 2022

Copy link to clipboard

Copied

Automate/Batch offers the override action save as checkbox.

Votes

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
Participant ,
Nov 02, 2022 Nov 02, 2022

Copy link to clipboard

Copied

LATEST

You are right, I can just record my action and use Batch to run it across all my files instead of loading them as layers and then saving each layer again, which took ages. Thank you!

Votes

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