Created
July 2, 2021 07:13
-
-
Save rajiteh/9d7ab9bcc2c4eedd1c0e637cb1d99e2d to your computer and use it in GitHub Desktop.
Tall Merge PSDs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ZERO = new UnitValue(0, 'px') | |
function appendToDoc(dstDoc, fileRef, isFirstDoc) { | |
const srcDoc = app.open(fileRef, undefined, true); | |
superSelect() | |
superCopy() | |
const dstDocWidth = new UnitValue(dstDoc.width.as('px') < srcDoc.width.as('px') ? srcDoc.width.as('px') : dstDoc.width.as('px'), 'px') | |
const dstDocHeight = new UnitValue(isFirstDoc ? srcDoc.height.as('px') : dstDoc.height.as('px') + srcDoc.height.as('px'), 'px') | |
const pasteTopLeftRightBottom = isFirstDoc ? [ZERO, ZERO, dstDocWidth, dstDocHeight] : [new UnitValue(dstDoc.height.as('px'), 'px'), ZERO, dstDocWidth, dstDocHeight] | |
srcDoc.close(SaveOptions.DONOTSAVECHANGES) | |
app.activeDocument = dstDoc | |
dstDoc.resizeCanvas(dstDocWidth, dstDocHeight, AnchorPosition.TOPCENTER); | |
selectRect(pasteTopLeftRightBottom[0], pasteTopLeftRightBottom[1], pasteTopLeftRightBottom[2], pasteTopLeftRightBottom[3]) | |
superPaste() | |
} | |
function selectRect(top, left, right, bottom) { | |
app.activeDocument.selection.select(Array( | |
Array(left, top), | |
Array(right, top), | |
Array(right, bottom), | |
Array(left, bottom) | |
), SelectionType.REPLACE) | |
} | |
function superSelect() { | |
var idselectAllLayers = stringIDToTypeID("selectAllLayers"); | |
var desc40 = new ActionDescriptor(); | |
var idnull = charIDToTypeID("null"); | |
var ref19 = new ActionReference(); | |
var idLyr = charIDToTypeID("Lyr "); | |
var idOrdn = charIDToTypeID("Ordn"); | |
var idTrgt = charIDToTypeID("Trgt"); | |
ref19.putEnumerated(idLyr, idOrdn, idTrgt); | |
desc40.putReference(idnull, ref19); | |
executeAction(idselectAllLayers, desc40, DialogModes.NO); | |
} | |
function superCopy() { | |
var idcopy = charIDToTypeID("copy"); | |
executeAction(idcopy, undefined, DialogModes.NO); | |
} | |
function superPaste() { | |
var idpast = charIDToTypeID("past"); | |
executeAction(idpast, undefined, DialogModes.NO); | |
} | |
const dstDoc = app.documents.add(10, 10, 300, "docRef", NewDocumentMode.RGB) | |
const fileList = File.openDialog("Select files to merge", "*.psd", true) | |
for (var i = 0; i < fileList.length; i++) { | |
appendToDoc(dstDoc, fileList[i], i == 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment