Skip to main content
Known Participant
December 28, 2022
Question

Way to turn on the next hidden layer to automate comps

  • December 28, 2022
  • 5 replies
  • 1780 views

Hi all,

I need to make 100s of layers comps across multiple files which involve making a comp, turning one layer off then turning the next layer on, making a new comp.

 

I've been able to make one where all the layers are just on and then I make a comp, turn the current layer off, make a new comp, etc but I now have layers with transparency so I have to turn each one on individually for each comp. Cycling through layers and turning visibility on doesn't seem to be a function as cycling only registers layers that are already on.

 

Maybe I'm missing something or there is a better way to do this? 

 

My current action is to have all the layers on, select the top on then hit the action:

- make layer comp

- turn off current layer

- select backward layer

then these 3 things are repeated a number of times in the action.

 

Any ideas?

 

Thanks!

This topic has been closed for replies.

5 replies

IsoneryumAuthor
Known Participant
January 9, 2023

Sorry everyone I have been out of action for a while, sorry for not keeping up with the comments etc. I really do appreciate everyone's assistance. Will update as soon as I can! Thanks for all your help and again, sorry for going silent.

Stephen Marsh
Community Expert
Community Expert
January 2, 2023

@Isoneryum – So how did the script go?

Stephen Marsh
Community Expert
Community Expert
December 29, 2022

@Isoneryum 

 

Try this script, it will automatically create a layer comp named after the layer for each child layer found in the currently selected/active parent layer group. A single undo step is offered if you need to undo all of the comps in one go. A quick test for 3 comps created manually was around 8 seconds, vs. around 0.1 of a second for the script (obviously less tedious as well).

 

/*
Create Layer Comps From Selected Parent Group Child Layers.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/way-to-turn-on-the-next-hidden-layer-to-automate-comps/td-p/13450230
v1.0 30th December 2022, Stephen Marsh
*/

#target photoshop

if (documents.length) {

    function main() {
        //if (activeDocument.activeLayer.typename === "LayerSet") {
        // Check for active layer group and case sensitive name of 'images'
        if (activeDocument.activeLayer.typename === "LayerSet" && activeDocument.activeLayer.name === "images") {

            // Setup the script timer
            var timeDiff = {
                setStartTime: function () {
                    d = new Date();
                    time = d.getTime();
                },
                getDiff: function () {
                    d = new Date();
                    t = d.getTime() - time;
                    time = d.getTime();
                    return t;
                }
            };
            timeDiff.setStartTime();

            // Set the current layer comp count
            var initialCompsCount = activeDocument.layerComps.length;

            /*
            // All child layers in the parent group should be hidden before comps are created
            for (var i = 0; i < activeDocument.activeLayer.layers.length; i++) {
                activeDocument.activeLayer.layers[i].visible = false;
            }
            */

            // Loop over the contents of the selected layer group and make layer comps
            for (var i = 0; i < activeDocument.activeLayer.layers.length; i++) {
                var layerName = activeDocument.activeLayer.layers[i].name;
                activeDocument.activeLayer.layers[i].visible = true;
                activeDocument.layerComps.add(layerName, undefined, true, true, true);
                activeDocument.activeLayer.layers[i].visible = false;
            }

            // Calculate the new layer comp count
            var compsCreatedCount = activeDocument.layerComps.length - initialCompsCount;

            // End of script notification
            alert(compsCreatedCount + " Layer Comps Created!" + "\n" + "(" + timeDiff.getDiff() / 1000 + " seconds)");

        } else {
            alert("The selected layer isn't a layer group or isn't named 'images'!");
        }
        
    }
    activeDocument.suspendHistory("Create Layer Comps From Selected Parent Group Child Layers...", "main()");

} else {
    alert("A document must be open to run this script!");
}

 

  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 as a plain text format file – Create Layer Comps From Selected Parent Group Child Layers.txt
  5. Rename the saved file extension from .txt to .jsx (i.e. Create Layer Comps From Selected Parent Group Child Layers.jsx)
  6. Install or browse to the .jsx file to run (see below)

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

Myra Ferguson
Community Expert
Community Expert
December 28, 2022

I'm wondering if you could incorporate the Make Frames From Layers command in your process. Make Frames From Layers is a feature that you would use to make frames for an animated GIF that does the following for you automatically when you start with only the bottom layer visible:

  1. Makes a frame in the Timeline for the current visible layer
  2. Turns the visibility for the current layer off
  3. Makes the next layer above the current layer visible
  4. Repeats steps 1-3 until it has gone through all of the layers

 

The resulting frames in the Timeline are similar to Layer Comps in that they are made up of visible layers. You could use those visible layers to create your Layer Comps.

 

To set it up, you would need to do the following:

  1. Show the Timeline (Window > Timeline)
  2. Click the Create Frame Animation button in the Timeline panel (if it's not showing, then use the dropdown menu)
  3. Go to the Timeline panel menu (the hamburger menu in the upper right of the Timeline)
  4. Hide all the layers except for the bottom one
  5. Select Make Frames From Layers
IsoneryumAuthor
Known Participant
December 29, 2022

Ah this sounds promising too. Can the frames then be exported as separate files to go one each to a page in an indesign doc? Will give it a try, thanks!

Myra Ferguson
Community Expert
Community Expert
January 7, 2023

You would need to make the layer comps from the frames, and then you could use File > Export > Layer Comps to Files.

 

But as I reread your question, it sounded like the layer comps may be made of single layers. If that's the case, then the simplest way to export them individually would be to do the following:

  1. Select all the layers in the Layers panel
  2. Right-click in the black space to the right of the layer names and select Export As... (or go to File > Export > Export As...)
  3. In the Export As dialog, make sure all the layers are selected and adjust settings for format, size, etc. as desired

 

If you need more than one layer exported, then you can group it with another layer and select the group instead of an individual layer when you select Export As...

Kevin Stohlmeyer
Community Expert
Community Expert
December 28, 2022

One thought is have you tried using groups when building to simplify the structure?

IsoneryumAuthor
Known Participant
December 28, 2022

All the background elements and other bits and pieces are in their relevant groups and then all the images/layers that need turning on and off are in their own group too. 

 

Do you mean to make each layer comp its own group? 

The file uses all the same elements for every layer comp, except the image that needs to change so duplicating everything else 50+ times would make the file crazy large 😕😕

 

So I actually have everything except the images as 3 or 4 layer comps which will form parent pages in indesign (the difference being one has 3 lines of colour on it, another has 3 different lines of colour, the others have 1 or 2 coloured lines). Then I have the group of images which I've layer comped on their own one at a time without anything else. Those are being added to my data merge But I had to go through and manually make layer comp, turn off layer, turn on next layer, make layer comp for all 50+ images in the file. 

Kevin Stohlmeyer
Community Expert
Community Expert
December 28, 2022

I would say make the modified items in one group all named the same thing. That way you could script it to show/hide specifically named groups. Hide group X save comp. Hide group Y save comp, etc. etc.