What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Reply to thread

I wonder if you mean something like the following script that will create a group for each selected layer with the group name same as the layer name.

To you select the layers you want to create groups of, then run the script.

[code]

//Requires Photoshop CS3 or better

#target photoshop;

if(documents.length){

var layerList = getSelectedLayersIdName();


for(var a in layerList){

activeDocument.layerSets.add().name=layerList[a][1].toString();

var ID = getLayerID();

moveLayerToLayerSet(Number(layerList[a][0]),ID);

}

if(app.version.match(/\d+/) >18)

executeAction( stringIDToTypeID( "collapseAllGroupsEvent"), undefined, DialogModes.NO );

}


function moveLayerToLayerSet( fromID, toID ){

backGroundCounter = activeDocument.artLayers[activeDocument.artLayers.length - 1].isBackgroundLayer ? 0 : 1;

var desc5 = new ActionDescriptor();

var ref4 = new ActionReference();

ref4.putIdentifier( charIDToTypeID('Lyr '), Number(fromID) );

desc5.putReference( charIDToTypeID('null'), ref4 );

var ref5 = new ActionReference();

ref5.putIndex( charIDToTypeID('Lyr '), getLayerIndexByID(toID)-Number(backGroundCounter) );

desc5.putReference( charIDToTypeID('T   '), ref5 );

desc5.putBoolean( charIDToTypeID('Adjs'), false );

desc5.putInteger( charIDToTypeID('Vrsn'), 5 );

try{

executeAction( charIDToTypeID('move'), desc5, DialogModes.NO );

}catch(e){alert(e);}

};

function getLayerIndexByID(ID){

var ref = new ActionReference();

ref.putIdentifier( charIDToTypeID('Lyr '), ID );

try{

activeDocument.backgroundLayer;

return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1;

}catch(e){

return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ));

}

};

function getLayerID(){

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );

return executeActionGet(ref).getInteger(stringIDToTypeID( "layerID" ));

}

function getSelectedLayersIdName(){

      var selectedLayers = new Array();

      var backGroundCounter = 1;

            if(activeDocument.artLayers.length > 0){

            backGroundCounter = activeDocument.artLayers[activeDocument.artLayers.length - 1].isBackgroundLayer ? 0 : 1;

            }

      var ref = new ActionReference();

      ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("targetLayers"));

      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++){

               selectedLayers.push(  desc.getReference( i ).getIndex() +backGroundCounter );

          } }

var results =[];

for(var a in selectedLayers){

var ref = new ActionReference();

ref.putIndex( charIDToTypeID( "Lyr " ), Number(selectedLayers[a]));

var desc =executeActionGet(ref);

var ID = desc.getInteger(stringIDToTypeID( "layerID" ));

var lName = desc.getString(charIDToTypeID( "Nm  "));

results.push([ID,lName]);

}

if(results.length<1){

    results.push([getLayerID(),activeDocument.activeLayer.name]);

    }

      return results;

};

[/code]


What is our favorite program/app? (Hint - it begins and ends with the letter P)
Back
Top