[jsx] Merge layers on Photoshop utility

I made a utility of Photoshop.
It is written in jsx(javascript file).

It makes each layer merge.
That means it remove layer’s filters and mask.

When I import designer’s photoshop data into Flash or Mobile project,
the filters and mask are not necessary.

Copy below text and paste into new file named merge.jsx(whatever you like).
And in Photoshop app,
Select menu
File > Scripts > Browse…
and select the file.
You must have seen the files without filters and masks.

Here is the code.

var doc = app.activeDocument;
mergeLayers(doc.layers);
alert('merge complete');

function mergeLayers(layers){
    var len = layers.length;
    var parent = layers.parent;
    var newLayer;
    for(var i = 0; i < len; i++){
        var layer = layers[i];
        if(layer.isBackgroundLayer){
            continue;
        }
        layer.allLocked = false;
        if(layer.typename == 'ArtLayer'){
            newLayer = parent.artLayers.add();
            newLayer.move(layer, ElementPlacement.PLACEAFTER);
            layer.merge();
        }
        else if(layer.typename == 'LayerSet'){
            mergeLayers(layer.layers);
        }
    }
}

Tags: , ,

Comments are closed.