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
  • 15052 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!

Kukurykus
Legend
August 6, 2021

These versions were due your to original question, but after I found you changed mind to make Smart Object I wrote forth code accordingly to your new requirement: Aug 06, 20121

 

Regarding to the speed when using these codes for merging the fastest is 1st, then 3rd & 2nd. When using the 2nd code to make a smart object from layers it is as fast as the 4th code 🙂

 

I didn't expect you to show up after over 2 months, but if you are here add one of my answers to correct (fastest) solutions for some stray forum scripting wanderers 😉

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. 

Kukurykus
Legend
August 6, 2021

I am making them Smart File, would it still work? 


 

(aD = activeDocument)
.suspendHistory('', '')
sTT = stringIDToTypeID
aHS = aD.activeHistoryState
ref2 = new ActionReference();
(ref1 = new ActionReference()).putEnumerated
(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);
ref2.putEnumerated(sTT('layer'), sTT('ordinal'), sTT('back'))
dsc.putReference(sTT('to'), ref2), executeAction(sTT('move'), dsc);
nme = ((lst = (lrs = aD.layers)[lrs.length - 1]).isBackgroundLayer ? lrs[lrs.length - 2] : lst).name
aD.activeHistoryState = aHS, runMenuItem(sTT('newPlacedLayer')), aD.activeLayer.name = nme