joonaspaakko / Batch-Mockup-Smart-Object-Replacement-photoshop-script

Batch Mockup Smart Object Replacement - Photoshop script - A script that can batch process multiple mockup files and is able to replace multiple smart objects per mockup.
97 stars 23 forks source link

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

Open ab781684 opened 2 months ago

ab781684 commented 2 months ago

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

joonaspaakko commented 2 months ago

The script doesn't interact with layer comps in any way. I'm thinking you would have to do File > Export > Layer comps to files, export them as PSD files and then process each file as a separate mockup psd by pointing to a folder in the option mockupPath, which will process all psd files in that folder using the same settings.

ab781684 commented 2 months ago

Apologies, this is a seperate ques, not related to mockup script. Can you pls answer it from pov of bulk layer comps updation. Thanks

ab781684 commented 2 months ago

if possible - can u write/modify script for same.

joonaspaakko commented 2 months ago

Sorry, I don't write scripts on demand, but maybe you might be able to find someone who would in the Adobe community forums.

I wrote this script in the past, maybe there's something there that you could reuse (there's a gif in the comments that shows how it works): https://gist.github.com/joonaspaakko/adbe208a867f8681afa86032f91f5099

ab781684 commented 2 months ago

No problems. Appreciate your swift replies. Thanks