Apply a selected layer to all layer comps

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: Patrick, Mike Hale, xbytor, Larry Ligon, Andrew, PS-Moderators

Apply a selected layer to all layer comps

Postby ChrisD » Tue Mar 06, 2012 4:56 pm

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".

Does anyone know haw to do this?

Any help would be so much appreciated!

Thanks in advance!

Chris
ChrisD
 
Posts: 1
Joined: Tue Mar 06, 2012 4:29 pm

Re: Apply a selected layer to all layer comps

Postby Paul MR » Tue Mar 06, 2012 8:47 pm

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

Code: Select all
#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;
};


and this will add the selected layer to selected layer comps...
Code: Select all
#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++ ){
    if( doc.layerComps[c].selected == true ){
   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;
};
Paul MR
 
Posts: 1472
Joined: Wed Oct 18, 2006 2:44 pm
Location: Bradford,UK

Re: Apply a selected layer to all layer comps

Postby mycort » Fri Apr 13, 2012 6:43 am

Truly great idea for a script because it is a painful task of updating many layer comps if you want to have a specific layer or folder to be visible, but I have a question.

1) Is it possible to combine the two scripts below?

2) aside from visibility control to all layer comps, is it possible to also script Update all layer comps when something is moved? I'd like to move something and update many comp layers all at once. Right now, you have to update one layer comp at a time. also, if this is possible, it would be nice to have all these functionality on one script.

Thx
mycort
 
Posts: 293
Joined: Sat Feb 04, 2012 7:51 pm

Re: Apply a selected layer to all layer comps

Postby mycort » Fri Apr 13, 2012 5:10 pm

Tried both script code snippets and I think I answered my own question of why you can't really combine these 2 scripts....unless there is a way to toggle this.

it seems like the selecting layer comps for update is the most useful, because you have the flexibility to select specific comps for visibility update or you can select all comps and update.

Aside from visibility control, Is it possible to update layer/folder "Position & Appearance(Blending Options)" too?
mycort
 
Posts: 293
Joined: Sat Feb 04, 2012 7:51 pm

Re: Apply a selected layer to all layer comps

Postby mycort » Fri Apr 13, 2012 8:12 pm

anyone? this is a big help if someone has any time to give.......thx a lot.
mycort
 
Posts: 293
Joined: Sat Feb 04, 2012 7:51 pm

Re: Apply a selected layer to all layer comps

Postby mycort » Mon Apr 16, 2012 7:27 am

Hi Mike,

I talked to Paul who originally created this code snippet and he said that he didn't know layer comps well enough for this to support position and appearance. Just wondering if you or anyone else know if it's possible to control these 2 for layer comp updates.

thx.
mycort
 
Posts: 293
Joined: Sat Feb 04, 2012 7:51 pm

Re: Apply a selected layer to all layer comps

Postby Mike Hale » Mon Apr 16, 2012 2:46 pm

Sorry, no I don't have any suggestions either. I also don't use layer comps much and the couple of times I looked at them I seem to remember there was very little scripting support for working with layer comps.
Mike Hale
Site Admin
 
Posts: 4318
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Re: Apply a selected layer to all layer comps

Postby mycort » Mon Apr 16, 2012 6:12 pm

ah, I see. Aside from visibility, positioning and appearance are supported by layer comps....So I don't see why it can't be controlled.

What about a code addition like this:

Current visibility control:
doc.activeLayer.visible=true;


Proposed Code snippet for position and appearance:
doc.activeLayer.position=true;

doc.activeLayer.appearance=true;

What about running a script listener when you updated a layer comp for when a layer is moved or the blending option is adjusted.....then use the recorded log file to extract or alter the code to support for this?
mycort
 
Posts: 293
Joined: Sat Feb 04, 2012 7:51 pm

Re: Apply a selected layer to all layer comps

Postby Mike Hale » Mon Apr 16, 2012 6:41 pm

mycort wrote:ah, I see. Aside from visibility, positioning and appearance are supported by layer comps....So I don't see why it can't be controlled.


There are lots of things you can do in the Photoshop GUI that are not scriptable.

And I am not saying that it can be done. I said that I don't have any suggestions on how to do this.
Mike Hale
Site Admin
 
Posts: 4318
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Re: Apply a selected layer to all layer comps

Postby mycort » Mon Apr 16, 2012 8:47 pm

ah, got it.

what about running a script listener based on position and appearance update for the layer comp, see what code you comeback with and make adjustments that way to make it workable?
mycort
 
Posts: 293
Joined: Sat Feb 04, 2012 7:51 pm

Re: Apply a selected layer to all layer comps

Postby mycort » Sun May 06, 2012 7:42 am

Just reposting this and hoping someone can really help with this......I know scripting layer comps are hard but what about using script listener to control not only visibilty but positioning and appearance too.

This is the biggest problem and pain of layer comps where if you have 10-40+ comps, it's very painful and tedious to update any global elements....

If anyone can help, truly would be the biggest help of all time......
mycort
 
Posts: 293
Joined: Sat Feb 04, 2012 7:51 pm

Re: Apply a selected layer to all layer comps

Postby patrickplaggenborg » Fri Dec 14, 2012 12:06 am

mycort wrote:This is the biggest problem and pain of layer comps where if you have 10-40+ comps, it's very painful and tedious to update any global elements....

This is the workaround I use:

1. Duplicate the selected Layers or Layer Groups.
2. Delete the original selected Layers or Layer Groups.
3. Select the newly created Layer or Layer Groups
4. Run the above script to update visibility across all (selected) Layer Comps.

This works. Would be even better if we could script step 1-2-3 as well. Anyone else?
patrickplaggenborg
 
Posts: 1
Joined: Tue Dec 11, 2012 11:58 am

Re: Apply a selected layer to all layer comps

Postby Ra9chelle » Fri Dec 14, 2012 1:01 am

this is a big help if someone has any time to give.......thx a lot.
Image
Image
Image
Image
Ra9chelle
 
Posts: 3
Joined: Thu Dec 13, 2012 3:08 am


Return to Help Me

Who is online

Users browsing this forum: No registered users and 1 guest