Skip to main content
merfer0590
Participant
September 28, 2020
Question

Need a script for merging Layers with the same names

  • September 28, 2020
  • 2 replies
  • 1088 views

 

Doing a project where I need to combine different views of shoe parts into one layer for a mask! I've ran a script to re order the layers alphabetically and yes I can go through and merge them by hand. But I would love a script that will combine liked names layers. Does anyone have something like this made? I'd love for it to run on the layers I've highlighted (around 200). As I have more liked names layers I would like to stay separate. Any help would be greatly appreciated! 

This topic has been closed for replies.

2 replies

Legend
September 29, 2020

EDIT 1: (with processing of hidden sections of groups)

#target photoshop

s2t = stringIDToTypeID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('numberOfLayers'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var len = executeActionGet(r).getInteger(p),
    lrs = {};

for (var i = 1; i <= len; i++) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('layerSection'));
    r.putIndex(s2t('layer'), i);
    if (typeIDToStringID(executeActionGet(r).getEnumerationValue(p)) == 'layerSectionEnd') continue;

    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('name'));
    r.putIndex(s2t('layer'), i);
    var n = executeActionGet(r).getString(p);

    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('layerID'));
    r.putIndex(s2t('layer'), i);
    var id = executeActionGet(r).getInteger(p);

    lrs[n]? lrs[n].push(id) : lrs[n] = [id]
}

for (a in lrs) {
    if (lrs[a].length > 1) {
        selectLayerByIDList(lrs[a])
        executeAction(s2t("mergeLayersNew"), new ActionDescriptor(), DialogModes.NO);
    }
}

function selectLayerByIDList(IDList) {
    var r = new ActionReference()
    for (var i = 0; i < IDList.length; i++) {
        r.putIdentifier(s2t("layer"), IDList[i])
    }
    var d = new ActionDescriptor()
    d.putReference(s2t("null"), r)
    executeAction(s2t("select"), d, DialogModes.NO)
}

 

Participant
September 8, 2023

@jazz-y Hi! Could you please help me write a script that merges layers with the same name but doesn't match substring + PSD has grouped layers so the hierarchy doesn't flat. I would be very grateful if you could help me!

JJMack
Community Expert
Community Expert
September 29, 2020

I do not think you will find a script like that is available for downloading. It not a common work flow users have. You will most likely need to program your own custom script for that process.

JJMack