Copy link to clipboard
Copied
I know how to export to each psd file using the photoshop variables.
But I want to know how to replicate artboards with the data in my csv file.
Assuming that you have a folder containing layered PSD files created from the data sets, you can try the following script to stack each PSD as an artboard, retaining the original layers from each separate PSD. This script is only intended for later CC versions and has been successfully tested in v2021, v2024 and v2025 on Mac and Win.
EDIT: Original code upated to v1.7 (20th August 2025)
/*
Stack Layered Files to Artboards.jsx
Stephen Marsh
v1.0 - 8th May 2024: Initial r
...
Copy link to clipboard
Copied
Variables/Data-driven graphics were around long before artboards. As you know, they only export to PSD as a native feature.
I am aware of an old custom script from the late Mike Hale to export directly to JPEG, so it is possible to extend variables via scripting. So perhaps somebody could directly script data sets to artboards.
You can make a feature request by making a new post and labelling it as an “idea" rather than a discussion:
I can envisage an indirect script that would take the output from the variable PSD exports and create a new layered file with an artboard for each separate PSD created from the variables.
Artboards have sizes, names, spacing, child layers/groups etc. They are sometimes complex for automation and I have a tough time working with them for scripting their position and spacing. The problem with my approach is that all artboards would be stacked one on top the other, they would not be arranged in a grid or vertically or horizontally. EDIT: Solved!
Thinking about this, it would probably just be easier to ignore the built-in variable feature and script the creation of artboard content from a CSV file.
Copy link to clipboard
Copied
Assuming that you have a folder containing layered PSD files created from the data sets, you can try the following script to stack each PSD as an artboard, retaining the original layers from each separate PSD. This script is only intended for later CC versions and has been successfully tested in v2021, v2024 and v2025 on Mac and Win.
EDIT: Original code upated to v1.7 (20th August 2025)
/*
Stack Layered Files to Artboards.jsx
Stephen Marsh
v1.0 - 8th May 2024: Initial release.
v1.1 - 9th May 2024: Added code to set the artboard background colour.
v1.2 - 13th August 2025: Reworked the selectAllLayers function. Reworked the smart object conversion code.
v1.3 - 14th August 2025: Added a step to unlock all selected floating layers before converting to a smart object. Various UX enhancements.
v1.4 - 15th August 2025: Artboard creation reworked to correctly handle content extending out of the artboard bounds. Smart objects are no longer used to dupe artboards.
v1.5 - 16th August 2025: Added checks to abort the script if artboards are detected in the input files.
v1.6 - 19th August 2025: Artboard arrangement modified: 0 = one single row, 1 = one single column, 2 = two columns etc. Digit validation check added to the column number prompt.
v1.7 - 20th August 2025: Code refactored, hopefully it's not broken! :]
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-export-to-artboards-using-the-photoshop-variables/td-p/14603249
Originally based on:
https://community.adobe.com/t5/photoshop-ecosystem/combining-mulitple-photoshop-files-into-1-photoshop-file-with-artboards/td-p/12218200
*/
// Global helpers
var c2t = function (s) { return app.charIDToTypeID(s); };
var s2t = function (s) { return app.stringIDToTypeID(s); };
#target photoshop
try {
if (app.documents.length === 0) {
(function () {
var origUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var inputFolder = Folder.selectDialog('Please select the input folder:');
if (inputFolder === null) {
app.beep();
return;
}
var inputFiles = inputFolder.getFiles(/\.(webp|avif|jpg|jpeg|tif|tiff|png|psd|psb)$/i);
inputFiles.sort(function (a, b) {
return decodeURI(a.name).toLowerCase().localeCompare(decodeURI(b.name).toLowerCase());
}).reverse();
// Open first file
var firstFile = app.open(File(inputFiles[0]));
if (checkForArtboardsAndAbort(firstFile)) return;
normalizeBackgroundLayer();
selectAllLayers();
applyLocking(true);
newArtboard();
app.activeDocument.duplicate("Artboard Stack from Files", false);
firstFile.close(SaveOptions.DONOTSAVECHANGES);
var artboardStack = app.activeDocument;
artboardStack.activeLayer.name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
// Process remaining files
for (var i = 1; i < inputFiles.length; i++) {
var remainingFile = app.open(File(inputFiles[i]));
if (checkForArtboardsAndAbort(remainingFile, artboardStack)) return;
normalizeBackgroundLayer();
selectAllLayers();
applyLocking(true);
newArtboard();
dupeToBaseDoc(remainingFile, artboardStack);
}
// Arrange & cleanup
app.beep();
arrangeArtboards();
app.activeDocument.trim(TrimType.TRANSPARENT);
app.preferences.rulerUnits = origUnits;
app.togglePalettes();
app.beep();
selectTool('artboardTool');
selectView("fitOnScreen");
selectView("zoomOut");
alert("Script completed!" + "\r\r" + "Manually arrange the artboards as required (Press Tab to restore the hidden panels).");
///// Functions /////
function normalizeBackgroundLayer() {
var layers = app.activeDocument.layers;
var layer = layers[layers.length - 1];
if (layer.isBackgroundLayer) layer.name = 'Background';
}
function checkForArtboardsAndAbort(docToClose, stackDoc) {
if (findArtboards().length > 0) {
alert("Artboards are not supported as input!");
docToClose.close(SaveOptions.DONOTSAVECHANGES);
if (stackDoc) stackDoc.close(SaveOptions.DONOTSAVECHANGES);
return true;
}
return false;
}
function selectAllLayers() {
try {
var doc = app.activeDocument;
var descriptor = new ActionDescriptor();
var reference2 = new ActionReference();
reference2.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(c2t("null"), reference2);
executeAction(s2t("selectAllLayers"), descriptor, DialogModes.NO);
if (doc.layers[doc.layers.length - 1].isBackgroundLayer) {
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putProperty(s2t("layer"), s2t("background"));
descriptor2.putReference(c2t("null"), reference);
descriptor2.putEnumerated(s2t("selectionModifier"), s2t("selectionModifierType"), s2t("addToSelection"));
descriptor2.putBoolean(s2t("makeVisible"), false);
executeAction(s2t("select"), descriptor2, DialogModes.NO);
}
} catch (e) {
alert("selectAllLayers() error!\r" + e + " " + e.line);
}
}
function applyLocking(protectNone) {
try {
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(c2t("null"), reference);
descriptor2.putBoolean(s2t("protectNone"), protectNone);
descriptor.putObject(s2t("layerLocking"), s2t("layerLocking"), descriptor2);
executeAction(s2t("applyLocking"), descriptor, DialogModes.NO);
} catch (e) {
alert("applyLocking() error!\r" + e + " " + e.line);
}
}
function arrangeArtboards() {
try {
var abLength = app.activeDocument.layerSets.length;
var theColumns = 1;
var space_x = 250;
var space_y = 250;
while (isNaN(theColumns = prompt("Arrange " + abLength + " artboards into a grid. \rEnter the number of columns (0 = one single row, 1 = one single column, 2 = two columns etc.):", theColumns))) {
if (theColumns === null || theColumns === "") {
alert('Script cancelled!');
return;
}
alert('Please enter a valid whole number!');
}
theColumns = parseInt(theColumns);
if (theColumns === 0) return;
if (theColumns < 1) theColumns = 1;
var theArtboards = [], w = 0, h = 0;
for (var i = 0; i < activeDocument.layerSets.length; i++) {
var r = new ActionReference();
r.putProperty(s2t("property"), s2t("artboardEnabled"));
r.putIdentifier(s2t("layer"), activeDocument.layerSets[i].id);
if (executeActionGet(r).getBoolean(s2t("artboardEnabled"))) {
var r2 = new ActionReference();
r2.putProperty(s2t("property"), s2t("artboard"));
r2.putIdentifier(s2t("layer"), activeDocument.layerSets[i].id);
var rect = executeActionGet(r2).getObjectValue(s2t("artboard")).getObjectValue(s2t("artboardRect"));
var l = rect.getDouble(s2t("left"));
var t = rect.getDouble(s2t("top"));
var rgt = rect.getDouble(s2t("right"));
var b = rect.getDouble(s2t("bottom"));
theArtboards.push([activeDocument.layerSets[i], [l, t, rgt, b]]);
var w1 = rgt - l, h1 = b - t;
if (w1 > w) w = w1;
if (h1 > h) h = h1;
}
}
var rows = Math.floor(theArtboards.length / theColumns);
if (rows * theColumns < theArtboards.length) rows++;
var i = 0;
for (var y = 0; y < rows; y++) {
var pos_y = y * (h + space_y);
for (var x = 0; x < theColumns; x++) {
if (i >= theArtboards.length) break;
activeDocument.activeLayer = theArtboards[i][0];
var pos_x = x * (w + space_x);
move(pos_x - theArtboards[i][1][0], pos_y - theArtboards[i][1][1]);
i++;
}
}
function move(x, y) {
try {
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
d.putReference(s2t("null"), r);
var d1 = new ActionDescriptor();
d1.putUnitDouble(s2t("horizontal"), s2t("pixelsUnit"), x);
d1.putUnitDouble(s2t("vertical"), s2t("pixelsUnit"), y);
d.putObject(s2t("to"), s2t("offset"), d1);
executeAction(s2t("move"), d, DialogModes.NO);
} catch (e) {
alert("arrangeArtboards.move() error!\r" + e + " " + e.line);
}
}
} catch (e) {
alert("arrangeArtboards() error!\r" + e + " " + e.line);
}
}
function artboardBackground(artboardColor) {
try {
var ideditArtboardEvent = s2t("editArtboardEvent");
var desc520 = new ActionDescriptor();
var ref129 = new ActionReference();
ref129.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
desc520.putReference(c2t("null"), ref129);
var desc521 = new ActionDescriptor();
var idcolor = s2t("color");
var desc523 = new ActionDescriptor();
desc523.putDouble(s2t("red"), 128);
desc523.putDouble(s2t("grain"), 128);
desc523.putDouble(s2t("blue"), 128);
desc521.putObject(idcolor, s2t("RGBColor"), desc523);
desc521.putInteger(s2t("artboardBackgroundType"), artboardColor);
desc520.putObject(s2t("artboard"), s2t("artboard"), desc521);
desc520.putInteger(s2t("changeBackground"), 1);
executeAction(ideditArtboardEvent, desc520, DialogModes.NO);
} catch (e) {
alert("artboardBackground() error!\r" + e + " " + e.line);
}
}
function selectTool(tool) {
try {
var desc9 = new ActionDescriptor();
var ref7 = new ActionReference();
ref7.putClass(s2t(tool));
desc9.putReference(c2t('null'), ref7);
executeAction(c2t('slct'), desc9, DialogModes.NO);
} catch (e) {
alert("selectTool() error!\r" + e + " " + e.line);
}
}
function selectView(menuItem) {
try {
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated(s2t("menuItemClass"), s2t("menuItemType"), s2t(menuItem));
descriptor.putReference(c2t("null"), reference);
executeAction(s2t("select"), descriptor, DialogModes.NO);
} catch (e) {
alert("selectView() error!\r" + e + " " + e.line);
}
}
function newArtboard() {
try {
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putClass(s2t("artboardSection"));
descriptor.putReference(c2t("null"), reference);
descriptor.putString(s2t("name"), app.activeDocument.name.replace(/\.[^\.]+$/, ''));
descriptor2.putDouble(s2t("top"), 0.0);
descriptor2.putDouble(s2t("left"), 0.0);
descriptor2.putDouble(s2t("bottom"), app.activeDocument.height.value);
descriptor2.putDouble(s2t("right"), app.activeDocument.width.value);
descriptor.putObject(s2t("artboardRect"), s2t("classFloatRect"), descriptor2);
executeAction(s2t("make"), descriptor, DialogModes.NO);
app.activeDocument.activeLayer.name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
artboardBackground(3);
} catch (e) {
alert("newArtboard() error!\r" + e + " " + e.line);
}
}
function dupeToBaseDoc(openFile, stackDoc) {
try {
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(c2t("null"), reference);
var reference2 = new ActionReference();
reference2.putName(s2t("document"), stackDoc.name);
descriptor.putReference(s2t("to"), reference2);
descriptor.putInteger(s2t("destinationDocumentID"), stackDoc.id); // dynamic doc ID
descriptor.putString(s2t("name"), app.activeDocument.name.replace(/\.[^\.]+$/, ''));
descriptor.putInteger(s2t("version"), 5);
executeAction(s2t("duplicate"), descriptor, DialogModes.NO);
openFile.close(SaveOptions.DONOTSAVECHANGES);
artboardBackground(3);
app.activeDocument.activeLayer = app.activeDocument.activeLayer.layers[0];
} catch (e) {
alert("dupeToBaseDoc() error!\r" + e + " " + e.line);
}
}
function findArtboards() {
try {
var layers = app.activeDocument.layers;
var artboards = [];
for (var i = 0; i < layers.length; i++) {
if (isArtboard(layers[i].id)) {
artboards.push(layers[i]);
}
}
return artboards;
function isArtboard(layerID) {
try {
var r = new ActionReference();
r.putIdentifier(s2t('layer'), layerID);
var options = executeActionGet(r);
return options.hasKey(s2t('artboard'));
} catch (e) {
return false;
}
}
} catch (e) {
alert("findArtboards() error!\r" + e + " " + e.line);
}
}
})();
} else {
alert('Please close all open files before running this script...');
}
} catch (e) {
alert("Error!\r" + e + " " + e.line);
}
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
Copy link to clipboard
Copied
Using latest version of PSD 26.9.0
Copy link to clipboard
Copied
Copy link to clipboard
Copied
OK I did - it only brought in one file then error message below
Copy link to clipboard
Copied
I have tested on v2025 on Win, with no errors. This may be due to your source files being different to mine, or a version difference issue. Let me take a look again...
Copy link to clipboard
Copied
@Todd_Morgan - Please try the 1.2b version updated above.
P.S. What version of Photoshop are you using?
Copy link to clipboard
Copied
using latest version
Copy link to clipboard
Copied
Copy link to clipboard
Copied
OK got it to work. The issue was the source files had locked BG layers, so I unlocked them and it worked!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TY @Stephen Marsh
Copy link to clipboard
Copied
OK got it to work. The issue was the source files had locked BG layers, so I unlocked them and it worked!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TY @Stephen Marsh
By @Todd_Morgan
That's great, glad you got there.
I'm testing on Win using the latest 2025 version as well, and one of my test files does have a Background layer. No such errors were triggered on my system.
I'll take a look at automating the conversion of Background layers, as the script already has a conditional check for the selection of these layers.
Just to be clear, you do mean a proper Background layer such as found when flattening? Not just a locked layer in the back?
Copy link to clipboard
Copied
Sorry - yes, locked layer, not an actual BG layer.
Copy link to clipboard
Copied
@Todd_Morgan wrote:
Sorry - yes, locked layer, not an actual BG layer.
Ah, well that's a different thing then, I didn't account for that and will now need do so!
Copy link to clipboard
Copied
I have now updated the code to a 1.3 version to account for locked layers, among other improvements.
Copy link to clipboard
Copied
Great!!!! Just tested and what is happening is it brings in one of the PSD files with a different artboard size if that file has anything that falls outside of the source file canvas. For example, if the source has a rectangle shape that is partly out of canvas area, when bringing into stack through the script, it creates a new artboard that encompasses the whole rectangle, instead of keeping the canvas size of the source and applying that to the new artboard. Make sense? Also, once the script has run, I need to reset my Workspace as it removes all tool/panels.
Copy link to clipboard
Copied
You can see here where that new artboard is not square (A)... (B) is same source but I deleted the layers that had content that went beyond the canvas in the source. The others don't have anything that goes outside canvas.
Copy link to clipboard
Copied
Also, once the script has run, I need to reset my Workspace as it removes all tool/panels.
By @Todd_Morgan
As the end of script notification states, artboard layout may need manual adjustments. To aid in this, panels are hidden and the zoom is changed to fit all artboards and the artboard tool is selected. I added this as my test files were using different size and orientations, so the initial grid layout wasn't economically nested (visually messy and larger file size due to larger canvas).
You don't need to reset your workspace to toggle the panels back on, just press the TAB key.
You can also remove or comment out the following line of code by prefixing it with double forward slashes:
app.togglePalettes();
Copy link to clipboard
Copied
I'll take a look at content extending outside of the original canvas bounds, my test files were clean.
Copy link to clipboard
Copied
I have just updated the previous code in my "Stack Layered Files to Artboards" script to version 1.4. This update should now correctly size the artboards to the original document's canvas, regardless of whether there is content extending beyond the original canvas bounds. Please test and let me know how it goes.
I had to rework some major parts of the code, the good news is that the script no longer leverages temporary smart objects, so it may run a little faster.
Copy link to clipboard
Copied
OK will give a try later today. YOU ROCK BTW!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Copy link to clipboard
Copied
All open nicely but then I ask for "1" in the column request at the end and this is what happens
but if I enter "5" I get this
Copy link to clipboard
Copied
@Todd_Morgan wrote:
All open nicely
Great! So the artboard sizing issue has been fixed, while retaining the elements which extend outside the artboard.
@Todd_Morgan wrote:
but then I ask for "1" in the column request at the end and this is what happens
but if I enter "5" I get this
@Todd_Morgan - I hate scripting artboard positioning!
I borrowed the code for the artboard grid layout from @r-bin
Does it work for 2 columns (it did for me)? The original code was intended for a grid based on column count, not a single column.
Copy link to clipboard
Copied
I have updated the code to a v1.6, feedback is appreciated... I'm pretty happy with how things have progressed based on your contributions, thank you!
The artboard arrangement prompt now defaults to 1.
Copy link to clipboard
Copied
For reference, this topic was on offshoot from:
Find more inspiration, events, and resources on the new Adobe Community
Explore Now