Try the below. I don't know how to get the copy merged to work. One of those things that's in the SDK, but can't seem to figure out. A work around is to merge visible then copy those. The last line of the code is commented out, but you can uncomment it so that you close your reference document and don't accidently save the merged layers. You would run into another problem in that when you paste, it will paste into the center of the new document. So I added a translate part that will move the new layer back to where the original was. #target photoshop app.bringToFront(); var docRef = activeDocument try{docRef.mergeVisibleLayers()} catch(e){} var moveAmt = docRef.activeLayer.bounds docRef.selection.selectAll(); docRef.selection.copy(); // want to grab all visible layers to clipboard var moveAmt = docRef.activeLayer.bounds var calcWidth = docRef.selection.bounds[2] - docRef.selection.bounds[0]; var calcHeight = docRef.selection.bounds[3] - docRef.selection.bounds[1]; var docResolution = docRef.resolution; var myNewDoc = app.documents.add(calcWidth, calcHeight, docResolution,undefined, NewDocumentMode.RGB, DocumentFill.TRANSPARENT); // the selection is the size of the FULL image, not the active region of the selection. myNewDoc.paste(); var newLayerBounds = myNewDoc.activeLayer.bounds myNewDoc.activeLayer.translate (moveAmt[0]-newLayerBounds[0], moveAmt[1]-newLayerBounds[1]) //docRef.close(SaveOptions.DONOTSAVECHANGES);
... View more