Auto Layer Comp Script

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

mycort

Auto Layer Comp Script

Post by mycort »

Hi, I have this script that will create layer comps from layers or folders.

The only problem is that it turns on both positioning and blending checkbox options for each layer comp it creates.

Is it possible to only turn on visibility, not positioning/blending checkbox options?

here's the code:
Code: Select all    #target Photoshop
    function main(){
    if(!documents.length) return;
    var doc = activeDocument;
    for(var c =0; c<doc.layers.length;c++){
       doc.activeLayer= doc.layers[c];
       doc.activeLayer.visible=false;
        }
    for(var a=doc.layers.length-1;a > -1;a--){
        doc.activeLayer= doc.layers[a];
        if(doc.activeLayer.isBackgroundLayer) continue;
         doc.activeLayer.visible=true;
         var Name = doc.activeLayer.name;
        doc.layerComps.add(Name, "",true, true, true);
        doc.activeLayer.visible=false;
        }
    doc.layerComps[0].apply();
    }
    main();
pfaffenbichler

Auto Layer Comp Script

Post by pfaffenbichler »

In ExtendScript Toolkit please check out
Help > Object Model Viewer
select your version of Photoshop and then select »LayerComps« in the Classes.

If you look up the Method »add« you should be able to figure out what the various boolean arguments in the line
Code: Select all        doc.layerComps.add(Name, "",true, true, true);
in your code affect and which one/s you may want to change to »false«.

Good luck!
mycort

Auto Layer Comp Script

Post by mycort »

great and thx, I think I know what to do.......
pdore4@videotron.ca
Posts: 1
Joined: Wed Aug 23, 2017 5:48 pm

Re: Auto Layer Comp Script

Post by pdore4@videotron.ca »

A correction is needed to get this to work properly

Code: Select all

        #target Photoshop
function main(){
if(!documents.length) return;
var doc = activeDocument;
for(var c =0; c<doc.layers.length;c++){
doc.activeLayer= doc.layers[c];
if(doc.activeLayer.isBackgroundLayer) continue; //added this line
doc.activeLayer.visible=false;
}
for(var a=doc.layers.length-1; a > -1; a--){
doc.activeLayer= doc.layers[a];
if(doc.activeLayer.isBackgroundLayer) continue;
doc.activeLayer.visible=true;
var Name = doc.activeLayer.name;
doc.layerComps.add(Name, "",true, true, true);
doc.activeLayer.visible=false;
}
doc.layerComps[0].apply();
}
main();