Is it possible to make the name of combined layers the bottom one's?

Contributor ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Sorry for the bad English in the title. What I mean is, for example I have 3 layers

top - Edit 2

mid - Edit

bot - Main layer with a name that makes sense

When I combine them together, the name of the combined layer becomes "Edit 2". Is it possible to make it the bottom one with a setting? Maybe with an action? 

(just to be clear, it is not always 3 layers and the names are not "Edit, Edit2" etc.)

TOPICS
How to

Views

7.3K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 4 Correct Answers

Adobe Community Professional , May 05, 2021 May 05, 2021
To you can automate that process with a Photoshop Script, Action can not use logic to see the Layer names  that are being merged and rename the merged layer name to what you want based on the former layer names.  Script can use the required logic to do what you wan to automate.

Likes

Translate

Translate
Adobe Community Professional , May 06, 2021 May 06, 2021
The previous script ran in approx. 6.7 seconds to run on a random set of 3 layers stacked. The new code below took approx. 4 seconds for the same 3 layers. It's still a less than ideal hack though... A better coder than me should be able to make this much faster. Can somebody upgrade my code? EDIT: It appears that the best/common way is to temporarily group the selected layers, then do something with the group (rather than with a new doc as my second script uses). /* Select all requi...

Likes

Translate

Translate
Contributor , May 07, 2021 May 07, 2021
I think making it run in 2 steps is a bad idea because purpose of the script is making it work with single click, and seamless if possible.  And, it is indeed possible. With some external help as well, I managed to write this. It works without opening SO (which I didn't like), but it can be a bit slower with bigger files (very little tho). I personally prefer this.   /* Create a new smart object with the bottom layer's name Gökhan Şimşek - 7.5.21 v1.1 */ #target photoshop var myDoc = app.ac...

Likes

Translate

Translate
Adobe Community Professional , May 07, 2021 May 07, 2021
I modified the get selected layers  code I posted to create the smart object layer,  As the cods stands the Smart object layer  name will be the bottom not the top name.  However, there is code that is commented out.  That code would make the layer name the list of merged layers. app.activeDocument.suspendHistory('makeSmartObject','main()'); function main() { try { var selectedLayers = get_selected_layers_id(); var Names = (get_layer_by_id(selectedLayers[0]).name); /* var Names = ""...

Likes

Translate

Translate
Adobe Community Professional ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

@Mugen777  Great job! That is what I was trying to achieve, however, without knowing how to use arrays I couldn't get there.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 08, 2021 May 08, 2021

Copy link to clipboard

Copied

LATEST

I had some experience from AE scripting, but the idea itself from someone else, so he deserves the credit here : )

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

I modified the get selected layers  code I posted to create the smart object layer,  As the cods stands the Smart object layer  name will be the bottom not the top name.  However, there is code that is commented out.  That code would make the layer name the list of merged layers.

 

app.activeDocument.suspendHistory('makeSmartObject','main()');

function main() {
	try {
		var selectedLayers = get_selected_layers_id();
		var	Names = (get_layer_by_id(selectedLayers[0]).name); 
		/*
		var Names = "";
		for ( var i = selectedLayers.length; i > 0; i-- ) { 
			thisLayer = get_layer_by_id(selectedLayers[i-1]);
			if (Names=="") Names = thisLayer.name;
			else Names = Names + "-" + thisLayer.name;
		}
		*/
		newPlacedLayer();
		app.activeDocument.activeLayer.name = Names;
	}
	catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }
} 

function get_selected_layers_id() {  
	try {  
		var r = new ActionReference();      
		r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("targetLayers"));      
		r.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));  
		var d = executeActionGet(r);  
		if (!d.hasKey(stringIDToTypeID("targetLayers"))) {  
			var r = new ActionReference();  
			r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerID"));      
			r.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));  
			return [ executeActionGet(r).getInteger(stringIDToTypeID("layerID")) ];  
        }  
		var list = d.getList(stringIDToTypeID("targetLayers"));  
		if (!list) return null;  
		var n = 0;  
		try { activeDocument.backgroundLayer } catch (e) { n = 1; }  
		var len = list.count;  
		var selected_layers = new Array();  
		for (var i = 0; i < len; i++) {  
			try {  
				var r = new ActionReference();  
				r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerID"));      
				r.putIndex( charIDToTypeID("Lyr "), list.getReference(i).getIndex() + n);  
				selected_layers.push(executeActionGet(r).getInteger(stringIDToTypeID("layerID")));  
			}  
			catch (e) { _alert(e); return null; }  
		}  
		return selected_layers;  
	}  
	catch (e) { alert(e); return null; }  
} 
 
function get_layer_by_id(id, doc_id) {    
	try {    
		var doc;  
		if (doc_id == undefined) doc = activeDocument;  
		else { 
			for (var i = 0; i < documents.length; i++) {  
				if (documents[i].id == doc_id) {  
					doc = documents[i];  
					break;  
                }  
            }
		}
		if (doc == undefined) { alert("Bad document " + doc_id); return null; }  
		var r = new ActionReference();      
		r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("json"));   
		if (doc_id == undefined) r.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));  
		else                     r.putIdentifier(charIDToTypeID("Dcmn"), doc_id);  
		eval("var json = " + executeActionGet(r).getString(stringIDToTypeID("json")));    
		if (json == undefined) return null;    
		var set = new Array();  
		function search_id(layers, id) {    
			for (var i = 0; i < layers.length; i++) {  
				if (layers[i].id == id) { set.push(i); return true; }  
            }  
			for (var i = 0; i < layers.length; i++) {  
				if (layers[i].layers) {    
					if (search_id(layers[i].layers, id)) { set.push(i); return true; }   
				}  
			}  
		}     
		if (search_id(json.layers, id)) {  
			var ret = doc.layers;  
			for (var i = set.length-1; i > 0; i--) { ret = ret[set[i]].layers;}  
			return ret[set[0]];  
		}  
		return null;  
	}    
	catch (e) { alert(e); }    
}

function newPlacedLayer() {
	executeAction( stringIDToTypeID( "newPlacedLayer" ), undefined, DialogModes.NO );
}

 

JJMack

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Nice one!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines