Skip to content

Trying to update 100's of Layer comps with a new layer in all of them at once. Can you pls script #36

@ab781684

Description

@ab781684

I have a photoshop file with about 20 – 30 layer comps. If I want to add a new item to the design and have it persistent across all layer comps I have to make it visible within each layer comp and update that layer comp separately. This is fine if you just have a few layer comps but when it the number goes up it can be really tedious.

I'm looking for some kind of script that will allow me to do this. A simple method might be highlighting a layer (or number of layers) and saying "make the highlighted layer(s) visible across all layer comps" or even better "make the highlighted layer(s) visible across all highlighted layer comps".

I found a script (as below) but what it restricts itself is to modify one selected layer can be applied to all of layer comps but can't include all of selected (new) layers to all layer comps at once. Second issue is position remains same (as before) in case of text string (unless its converted to smart object).

Any help would be so much appreciated!

This will add the selected layer to all layer comps...

Code:

#target Photoshop

function main(){
if(!documents.length) return;
var newLayer = getSelectedLayersIdx()[0];
var doc = app.activeDocument;
for( var c = 0; c < doc.layerComps.length; c++ ){
doc.layerComps[c].apply();
makeActiveByIndex( Number(newLayer), true );
doc.activeLayer.visible=true;
doc.layerComps[c].recapture();
}
}
main();
function makeActiveByIndex( idx, visible ){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putIndex(charIDToTypeID( "Lyr " ), idx)
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), visible );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};

function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
}
return selectedLayers;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions