Skip to main content
Mugen777
Inspiring
May 5, 2021
해결됨

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

  • May 5, 2021
  • 2 답변들
  • 15088 조회

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

이 주제는 답변이 닫혔습니다.
최고의 답변: 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 답변

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
Mugen777작성자
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
Mugen777작성자
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. 

JJMack
Community Expert
Community Expert
May 7, 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.activeDocument.activeLayer.parent;
var myId = app.activeDocument.activeLayer.id;
var mainArray;
var beforeArray;
var afterArray;
var indexNum;
var diff;
var newName;

// Array function that creates array from the all layers 1.1
function createArray(doc){
    var myLength= doc.layers.length;
    for(i=0; i<myLength; i++){
        mainArray.push(doc.layers[i].name);
        if(doc.layers[i].id == myId){
            indexNum = i;
        }
    }
    return mainArray;
}

function main(){
    //First Array
    mainArray= [];
    beforeArray = createArray(myDoc);

    // Convert the selected layers to an embedded Smart Object
    executeAction(stringIDToTypeID("newPlacedLayer"), undefined, DialogModes.NO);

    //New Array
    mainArray= [];
    afterArray = createArray(myDoc);

    //Length Difference
    diff = beforeArray.length - afterArray.length;

    // Set the new name - 1.1
    newName= beforeArray[indexNum+diff];

    // Rename the Smart Object
    app.activeDocument.activeLayer.name = newName;
}

//To undo with single move
app.activeDocument.suspendHistory ("Smart Obj Script", "main()");

 


I made it undo friendly as well. I personally satisfied : D Thank you for all your help, it helped a lot to create this version : )


Here is the mergeDown.jsx  I wrote you could script that would also merge the layer names as well as the layers contents.  Just target the top layer an press the shortcut you set for the script  you could change Ctrl+E to be the Scripts shortcut.  You can coment out the alert in the script if you want to.

 

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

function main() {
	try {
		topLayer = app.activeDocument.activeLayer.name;
		mergeDown();
		app.activeDocument.activeLayer.name = topLayer + " - " + app.activeDocument.activeLayer.name;
	}
	catch(e) {alert("Nothing Merged");}
} 

function mergeDown() {
	var descriptor = new ActionDescriptor();
	executeAction( stringIDToTypeID( "mergeLayersNew" ), descriptor, DialogModes.NO );
}

 

Here I used the shortcut twice.  You can also backout  the script with an undo,

 

 

JJMack