• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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
Actions and scripting

Views

11.5K

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 6 Correct answers

Community Expert , 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.

Votes

Translate

Translate
Community Expert , 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
...

Votes

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.active
...

Votes

Translate

Translate
Community Expert , 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 = ""
...

Votes

Translate

Translate
LEGEND , Aug 05, 2021 Aug 05, 2021

 

sTT = stringIDToTypeID;
(ref = new ActionReference()).putEnumerated
(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref)
executeAction(sTT('linkSelectedLayers'), dsc)
with((actveDcmnt = activeDocument).activeLayer)
	nme = linkedLayers.pop().name, merge()
actveDcmnt.activeLayer.name = nme

 

or:

 

(aD = activeDocument).suspendHistory('', ''), aHS = aD.activeHistoryState
	sTT = stringIDToTypeID, dsc = new ActionDescriptor(), arr = ['back
...

Votes

Translate

Translate
Guide , Aug 07, 2021 Aug 07, 2021

I did not see the simplest way - to get the name of the 1st target layer and assign it after convert to SO.

 

function main() {
	var s2t = stringIDToTypeID;

	(tr = new ActionReference).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
	tr.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

	(lr = new ActionReference).putProperty(s2t('property'), n = s2t('name'));
	lr.putIdentifier(s2t('layer'), executeActionGet(tr).getList(p).getReference(0).getIdentifier(s2t('layerID')));
...

Votes

Translate

Translate
Adobe
Contributor ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

It is fast when there are 10 layers but when the numbers become 100+, you feel the difference 😕 

I honestly have no idea how yours work, but mine is basically create 2 arrays with for then compare them to find difference. And since it is a loop, it gets slower with more layers. 

Votes

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
Guide ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

I did not see the simplest way - to get the name of the 1st target layer and assign it after convert to SO.

 

function main() {
	var s2t = stringIDToTypeID;

	(tr = new ActionReference).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
	tr.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

	(lr = new ActionReference).putProperty(s2t('property'), n = s2t('name'));
	lr.putIdentifier(s2t('layer'), executeActionGet(tr).getList(p).getReference(0).getIdentifier(s2t('layerID')));
	var nm = executeActionGet(lr).getString(n)

	executeAction(s2t('newPlacedLayer'), undefined, DialogModes.NO);

	(r = new ActionReference()).putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
	(d = new ActionDescriptor()).putReference(s2t("null"), r);
	(d1 = new ActionDescriptor()).putString(s2t("name"), nm);
	d.putObject(s2t("to"), s2t("layer"), d1);
	executeAction(s2t("set"), d, DialogModes.NO);
}

app.activeDocument.suspendHistory("Smart Obj Script", "main()");

 

Votes

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
LEGEND ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

That is surely the fastest method, but it is too obvious 😉

I like much more slower but unconventional soutions 😄

Votes

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 ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

Its been a while so I am not %100 sure, but I remember I couldn't find a way to get that bottom layer's name (and I believe all answers above use some kind of trick as well)

But if it is possible, it would be indeed the fastest and simplest. 

To be honest I couldn't understand how your code does that, but looks like it works and it is enough to make me happy : ) 

Thanks! 

(we will have to most correct answers award haha : )

Votes

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
LEGEND ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

It's easy. Action Manager as opposed to DOM reads layers from the most bottom.

Votes

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
LEGEND ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

I tried up to 10 layers, so you probably are right. That might be slower for hundreds items.

Votes

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