Skip to main content
Mugen777
Inspiring
May 5, 2021
Answered

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

  • May 5, 2021
  • 2 replies
  • 15086 views

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

This topic has been closed for replies.
Correct answer jazz-y

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. 


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()");

 

2 replies

Kukurykus
Legend
August 6, 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', 'for']; while(arr.length)
		(ref = new ActionReference()).putEnumerated(sTT('layer'), sTT('ordinal'), sTT(arr.shift() + 'wardEnum')),
		dsc.putReference(sTT('null'), ref), executeAction(sTT('select'), dsc); nme = aD.activeLayer.name
aD.activeHistoryState = aHS, (lyr = aD.activeLayer).merge(), aD.activeLayer.name = nme

 

or else:

 

sTT = stringIDToTypeID;
(ref = new ActionReference()).putEnumerated
(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref)
executeAction(sTT('groupLayersEvent'), dsc), aD.activeLayer.merge()
.name = (lrs = (aD = activeDocument).activeLayer.layers)[lrs.length - 1].name

 

Mugen777
Mugen777Author
Inspiring
August 6, 2021

Hey there


Looks like it is faster than what I created before, I just changed 

    (lyr = aD.activeLayer).merge()

with 

    executeAction(stringIDToTypeID("newPlacedLayer"), undefined, DialogModes.NO)

to turn layers to smart object instead, and looks like it is lot better than before : ) 

Thank you!

Mugen777
Mugen777Author
Inspiring
August 7, 2021

I was able to reproduce the issue with your (previously my 2nd) code on later duplicated layers. Like I said you cannot use suspendHistory() method inside other suspendHistory() method. Mine code already used this method, but then you put the whole code inside your function that uses it too. Just remove your main function, or make it regular function, so without suspendHistory method, and it will work 😉


In 4th code I also found what is problem. From your previous posts that didn't seem you will use selected layers contained in groups, so I made script for zero level layers. If you want it worked for both cases change:

 

lrs = aD.layers

 

to:

 

lrs = aD.activeLayer.parent.layers

 


Looks like both of them work now 🙂 

But the thing is, I was using that main function to undo whole thing with only one ctrl-z. (I use undo a LoT). Anything I can do about it? 

And I am just curious, 4.th code always shows this error. I am just curious what is it. 

 

Derek Cross
Community Expert
Community Expert
May 5, 2021

In the Layers panel, you can drag the layers to change the order, and you can relabel the layers.

 

 

Mugen777
Mugen777Author
Inspiring
May 5, 2021

So far I was renaming layers after combining them, but it takes a lot of time, so I thought maybe there is a way to change that setting. 

Derek Cross
Community Expert
Community Expert
May 5, 2021

Cmd + Option + Shift + E (Mac) merges the layers to one layer (keeping the individual layers).