marc_edwards's profile

133 Messages

 • 

5.1K Points

Sun, Apr 3, 2011 7:55 AM

Closed

Implemented

Photoshop: Smarter layer names when merging

When merging layers, the top layer’s name is used for the result. It would be really nice if the topmost layer with a non-“Layer n” (where n is a number) name was used, keeping the topmost user-entered layer name. As it stands today, merging layers usually requires retyping in the layer name straight afterwards.

129 Messages

 • 

3.2K Points

11 y ago

Here's a script I put together (several of the functions from Mike Hale). If you put it in photoshop/presets/scripts/ you can assign it to Cmd/Ctrl-E.

It only looks at the name of selected layers, not layers inside a selected group.
It not only tries to not use "Layer N" but also anything else generated: adjustment layers, shape layers, fill layers, and groups.

It can merge layers, merge down and merge groups.

http://sites.google.com/site/davidjen...

133 Messages

 • 

5.1K Points

Thanks David. Your scripts are great!

3 Messages

 • 

82 Points

Hi David,
Would it be possible of you to revise the script so that when merging layers (and layer groups) the resulting merged layer is named with the bottom most layer's name? Thats would be very useful for me.
Thanks, in advance!

--Sheldon.

129 Messages

 • 

3.2K Points

Here you go. It names the merged layer based on the lowest selected layer with a user created name, or just the bottom selected layer if there is no user created layer name.
http://sites.google.com/site/davidjen...

3 Messages

 • 

82 Points

Awesome, but doesn't always work as expected. if I show you some cases where it doesn't work, are you interested in tweaking it?

Thanks, Sheldon.

129 Messages

 • 

3.2K Points

Sure.
Is it a problem with layer sets? Currently, only items that are highlighted are taken into account when naming.

129 Messages

 • 

3.2K Points

9 y ago

This feature is now in in Photoshop CS6 13.0.2! That's the Retina update for those who aren't Creative Cloud subscribers. I guess one CC feature slipped through.

I noticed this when I was trying to update my script for CS6 :-P

3 Messages

 • 

82 Points

9 y ago

hey, thats great!
also, thanks again for your work on this before.

Sheldon.

125 Messages

 • 

2K Points

7 y ago

Would be very useful.
However, my CS6 Extended (13.0.6) on OSX 10.6.8 does not "include" this.

Second script works, but only if you don't select the bottom layer (Unless it's the "Background" layer...

Any solution?

125 Messages

 • 

2K Points

7 y ago

Okay, edited the script. Problem was that, if there wasn't a BG layer, the script tried to fill the array with a value for layers[0] (reserved for Background layer), where the lowest existing layer was layers[1]. That gave an error.

Since I only needed the script to rename the merged layer to whatever was the lowest selected layers name (I always name my layers), the script could get a bit simpler.

Resulting script, for those who are interested:
#target photoshop
//created by David Jensen, edit by René Damkot

var bottomName = 'Bg'
var BG = 0
var L=app.activeDocument.layers.length;
app.activeDocument.suspendHistory('Merge Layers René', 'main()');
function main(){
x=getSelectedLayerNames(); // get array of layerNames
bottomName=x[0]; // get name of the lowest selected layer
executeAction( charIDToTypeID( "Mrg2" ), undefined, DialogModes.NO ); //merge
if ( activeDocument.activeLayer.name!='Background') { //only rename if it isn't a BG, so a BG layer stays locked
activeDocument.activeLayer.name=bottomName;
}

////// Mike Hale from ps-scripts.com wrote the following functions
function getSelectedLayerNames(){
var names = [];
var selectedIdxs = getSelectedLayersIdx();
for(var l =0; l < selectedIdxs.length; l++ ){
names.push( getLayerNameByIndex( selectedIdxs[ l ] ) );
}
return names;
}
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
if (activeDocument.layers[L-1].name!='Background') { // test if the file has a 'Background' at the bottom
BG=1; // if not, we cannot test the name of layer[0], so we need layer[1]
}
var selectedLayers = new Array();
for(var i=BG;i<c;i++){ // work up from the bottom layer
selectedLayers.push( desc.getReference( i ).getIndex() );
}
}else{
try{
activeDocument.backgroundLayer;
var mod = 1;
}catch(e){
var mod = 0
}
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-mod);
}
return selectedLayers;
}
function getLayerNameByIndex( idx ) {
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Nm " ));
ref.putIndex( charIDToTypeID( "Lyr " ), idx );
return executeActionGet(ref).getString(charIDToTypeID( "Nm " ));;
}
}

67 Messages

 • 

1.1K Points

5 y ago

I tried this script with Photoshop CC 2015 but it gives me an error 1220:

Line: 56->  ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Nm " )); 

Any thoughts?