Layer Set Groups

Upload Photoshop Scripts, download Photoshop Scripts, Discussion and Support of Photoshop Scripts

Moderators: Tom, Kukurykus

Paul MR

Layer Set Groups

Post by Paul MR »

Photoshop CS4 or better

This script will allow you to save selected layers so that they may be recalled/selected
You can have as many sets as you like.
Removal of set is supported.
Layers can be moved and they will still be selected if part of a set.
All the information is held within the documents metadata.
Jeremy Knudsen

Layer Set Groups

Post by Jeremy Knudsen »

Interesting usage of per layer XMP metadata. I did find a minor bug when you define a Preset that contains the Background layer having been selected. When using the Preset it doesn't set the selection of the background layer (an alert pops up saying the layer is not found--at least the background layer exception is handled).
Paul MR

Layer Set Groups

Post by Paul MR »

Nice catch, to fix that problem change line 148

from:
Code: Select allif(result != true){
to
Code: Select allif(result > 0){
Jeremy Knudsen

Layer Set Groups

Post by Jeremy Knudsen »

Hi Paul,

I think I found one more bug in your code.

If the layer in the layer set is not found, instead of returning true...
Code: Select allfunction getLayerItemIndexByLayerID(id) {
    var ref = new ActionReference();
    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
    ref.putIdentifier( charIDToTypeID( "Lyr " ), id );
   try{
    return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ));
   }catch(e){return true;}
};


...I think you want to return false:

Code: Select allfunction getLayerItemIndexByLayerID(id) {
    var ref = new ActionReference();
    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
    ref.putIdentifier( charIDToTypeID( "Lyr " ), id );
   try{
    return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ));
   }catch(e){return false;}
};


This way, the selLayer method that calls the method above will display the 'Layer does not exist' message:
Code: Select allfunction selLayer(layerID,add) {
var result = getLayerItemIndexByLayerID(layerID);
if (result > 0) {
    try{
        activeDocument.backgroundLayer;
        var bkGround = 1;
    } catch(e) {var bkGround = 0;}
        selectLayerByIndex(result - bkGround ,add);
   } else {
        alert("Layer does not exist");      
    }
};