skip to Main Content

The activeDocument.mergeVisibleLayers(); command simply flattens the image to the Background layer.

I am looking for a way to merge all layers to a new layer which stays on top of all other layers, like the Layer->Merge Visible (Ctrl+Shift+E) Photoshop command.

Is that possible?

2

Answers


  1. Chosen as BEST ANSWER

    Not sure if this is the best solution but it worked for me:

    // Copy all visible layers to clipboard (true = merged)
    activeDocument.activeLayer.copy(true);
    // then paste them (creates a new layer)
    activeDocument.paste();
    

  2. The answer by George does not work well with tranparent images (it crops the transparency and aligns the pasted image to the middle). Here is a script that simply executes the Merge Visible command, found with the Scripting Listener plug-in:

    var idMrgV = charIDToTypeID("MrgV");
    executeAction(idMrgV, undefined, DialogModes.NO);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search