Skip to content

Commit

Permalink
feat: add psd export support
Browse files Browse the repository at this point in the history
* add additional string substitution
  • Loading branch information
Hanna Walter committed Jul 20, 2021
1 parent caeed2c commit 1ab128e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 12 deletions.
47 changes: 38 additions & 9 deletions Export Layers To Files (Fast).jsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ var Formats = {
return options;
}
},
"PSD": {
index: 5,
fileType: "PSD",
fileExtension: ".psd",
formatArgs: function() {
var options = new PhotoshopSaveOptions();
options.layers = false;
return options;
}
}
}

var Matte = {
Expand Down Expand Up @@ -371,6 +381,7 @@ function main() {

// show dialog
if (showDialog() === 1) {
prefs.documentName = app.activeDocument.name.split('.')[0];
env.documentCopy = app.activeDocument.duplicate();

// collect layers
Expand Down Expand Up @@ -809,14 +820,25 @@ function makeFileNameFromLayerName(layer, stripExt, withGroup, index) {

function getUniqueFileName(fileName, layer, index) {
var ext = prefs.fileExtension;

var date = new Date();
// These are all the valid formattings supported by prefix/suffix
var replacements = [
["{i}", index],
["{ii}", padder(index, 2)],
["{iii}", padder(index, 3)],
["{iiii}", padder(index, 4)],
["{n}", layer.layer.name],
["{ln}", layer.layer.name],
["{dn}", prefs.documentName],
["{M}", (date.getMonth() + 1)],
["{MM}", padder(date.getMonth() + 1, 2)],
["{D}", date.getDate()],
["{DD}",padder(date.getDate(), 2)],
["{YY}", ("" + date.getFullYear()).substring(2)],
["{YYYY}", date.getFullYear()],
["{HH}", padder(date.getHours(), 2)],
["{mm}", padder(date.getMinutes(), 2)],
["{ss}", padder(date.getSeconds(), 2)],
["{sss}", padder(date.getMilliseconds(), 3)],
];

var outputPrefix = prefs.outputPrefix;
Expand Down Expand Up @@ -2346,6 +2368,7 @@ function getDialogFields(dialog) {
}

function makeMainDialog() {

// DIALOG
// ======
var dialog = new Window("dialog", undefined, undefined, {closeButton: false, resizeable: true});
Expand Down Expand Up @@ -2984,10 +3007,6 @@ function makeMainDialog() {
tabBmp.spacing = 5;
tabBmp.margins = 10;

// TABPNLEXPORTOPTIONS
// ===================
tabpnlExportOptions.selection = tabPng24;

// GRPBMPDEPTH
// ===========
var grpBmpDepth = tabBmp.add("group", undefined, {name: "grpBmpDepth"});
Expand All @@ -3014,6 +3033,19 @@ function makeMainDialog() {
var cbBmpFlipRowOrder = tabBmp.add("checkbox", undefined, undefined, {name: "cbBmpFlipRowOrder"});
cbBmpFlipRowOrder.text = "Flip Row Order";

// PSD
// ===
var PSD = tabpnlExportOptions.add("tab", undefined, undefined, {name: "PSD"});
PSD.text = "PSD";
PSD.orientation = "column";
PSD.alignChildren = ["left","top"];
PSD.spacing = 10;
PSD.margins = 10;

// TABPNLEXPORTOPTIONS
// ===================
tabpnlExportOptions.selection = PSD;

// DIALOG
// ======
var lblMetadata = dialog.add("statictext", undefined, undefined, {name: "lblMetadata"});
Expand All @@ -3028,8 +3060,5 @@ function makeMainDialog() {
lblContact.add("statictext", undefined, "To get the most recent version, or leave feedback, go to:", {name: "lblContact"});
lblContact.add("statictext", undefined, "https://github.com/hsw107/Photoshop-Export-Layers-to-Files-Fast", {name: "lblContact"});




return dialog;
}
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Some of the features of the script include...
- JPEG
- Targa
- BMP
- PSD
- Handles nesting in grouped layers
- Export either all layers or visible only
- Files are named either using layer names, layer + group names, or automatic layer indices
Expand Down Expand Up @@ -93,7 +94,18 @@ Prefix and Suffix fields can take the following string substitutes.
| `{ii}` | Will be replaced with the index of the layer, with a leading zero |
| `{iii}` | Will be replaced with the index of the layer, with up to two leading zeros |
| `{iiii}` | Will be replaced with the index of the layer, with up to three leading zeros |
| `{n}` | Will be replaced with the layer name. Useful for when exporting filenames as their index |
| `{ln}` | Will be replaced with the layer name. Useful for when exporting filenames as their index |
| `{dn}` | Will be replaced with the document name |
| `{M}` | Will be replaced with the month |
| `{MM}` | Will be replaced with the month, with a leading zero |
| `{D}` | Will be replaced with the date of the month |
| `{DD}` | Will be replaced with the date of the month, with a leading zero |
| `{YY}` | Will be replaced with the year, as the last two digits |
| `{YYYY}` | Will be replaced with the year, as all four |
| `{HH}` | Will be replaced with the hours, with a leading zero |
| `{mm}` | Will be replaced with the minutes, with a leading zero |
| `{ss}` | Will be replaced with the seconds, with a leading zero |
| `{sss}` | Will be replaced with the milliseconds, with leading zeros |

### Known Gaps

Expand Down
10 changes: 9 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Changelog

## v2.1

_Release Date: 19 July, 2021_

- Add more string substitution to the prefix/suffix fields https://github.com/hsw107/Photoshop-Export-Layers-to-Files-Fast/issues/71
- Renamed string substitution `{n}` to `{ln}`
- Add PSD export support https://github.com/hsw107/Photoshop-Export-Layers-to-Files-Fast/issues/92

## v2.0

_Release Date: SOON_
_Release Date: 19 July, 2021_

- New smaller, and hopefully easier to use UI
- "Visible only" is now a checkbox (can use with "All Layers" or "Selected Group") https://github.com/hsw107/Photoshop-Export-Layers-to-Files-Fast/issues/91
Expand Down
2 changes: 1 addition & 1 deletion dev/dialog.js

Large diffs are not rendered by default.

0 comments on commit 1ab128e

Please sign in to comment.