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!

Auto Name Group based on Layer Names?


James Pyle

Member
Messages
18
Likes
1
Is it possible to automatically name a Group based on layer name when you group it? Or a script that can do this.

I need the groups to be named but I have about 500 named layers to group and don't want to have to type in the name 500 times....

Thanks :)
 

ph_o_e_n_ix

Well-Known Member
Messages
119
Likes
138
It's not clear what you want ... something like this?


If not, explain it in detail or show some examples...
 

Dormeur74

Power User
Messages
204
Likes
180
I think it is possible, but your need is indeed not clear. Would it be possible for you to make us a screenshot of some layers to group with the name of the layers and their groups. Just a little simulation would be worth all the explanations.
 

Paul MR

The Script Master
Messages
382
Likes
206
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; 
};
 

Top