Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore mode #224

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 88 additions & 33 deletions Export Layers To Files (Fast).jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ app.bringToFront();
// Type definitions
//

var PrefixSelectionMode = {
IGNORE_PREFIXED: 1,
ONLY_PREFIXED: 2,

values: function() {
return [this.IGNORE_PREFIXED, this.ONLY_PREFIXED];
},

forIndex: function(index) {
return this.values()[index];
},

getIndex: function(value) {
return indexOf(this.values(), value);
}
};

var FileNameType = {
AS_LAYERS: 1,
INDEX_ASC: 2,
Expand Down Expand Up @@ -354,8 +371,9 @@ var DEFAULT_SETTINGS = {
exportLayerTarget: app.stringIDToTypeID("exportLayerTarget"),
fileType: app.stringIDToTypeID("fileType"),
groupsAsFolders: app.stringIDToTypeID("groupsAsFolders"),
ignoreLayers: app.stringIDToTypeID('ignoreLayers'),
ignoreLayersString: app.stringIDToTypeID('ignoreLayersString'),
ignoreModeEnabled: app.stringIDToTypeID('ignoreModeEnabled'),
ignoreModeString: app.stringIDToTypeID('ignoreModeString'),
ignoreModeSelection: app.stringIDToTypeID('ignoreModeSelection'),
jpgQuality: app.stringIDToTypeID('jpgQuality'),
jpgMatte: app.stringIDToTypeID('jpgMatte'),
jpgIcc: app.stringIDToTypeID('jpgIcc'),
Expand Down Expand Up @@ -643,10 +661,16 @@ function exportLayers(exportLayerTarget, progressBarWindow) {
for (var i = (prefs.exportForeground ? 1 : 0); i < count; ++i) {
var layer = layersToExport[i].layer;

// Ignore layers that have are prefixed with ignoreLayersString
if (prefs.ignoreLayers
&& prefs.ignoreLayersString.length > 0
&& layer.name.indexOf(prefs.ignoreLayersString) === 0) continue;
// Ignore layers that have are prefixed with ignoreModeString
if ((prefs.ignoreModeEnabled
&& prefs.ignoreModeSelection == PrefixSelectionMode.IGNORE_PREFIXED
&& prefs.ignoreModeString.length > 0
&& layer.name.indexOf(prefs.ignoreModeString) === 0)
|| (prefs.ignoreModeEnabled
&& prefs.ignoreModeSelection == PrefixSelectionMode.ONLY_PREFIXED
&& prefs.ignoreModeString.length > 0
&& layer.name.indexOf(prefs.ignoreModeString) !== 0)) continue;


var fileName;
switch (prefs.nameFiles) {
Expand Down Expand Up @@ -1220,12 +1244,18 @@ function showDialog() {

fields.cbVisibleOnly.enabled = (visibleLayerCount > 0);
fields.cbVisibleOnly.value = prefs.visibleOnly;
fields.cbIgnorePrefix.value = prefs.ignoreLayers;
fields.txtIgnorePrefix.enabled = prefs.ignoreLayers;

fields.txtIgnorePrefix.text = prefs.ignoreLayersString;
fields.cbIgnorePrefix.onClick = function() {
fields.txtIgnorePrefix.enabled = this.value;

fields.cbIgnoreModeSelectionEnabled.value = prefs.ignoreModeEnabled;
fields.txtIgnoreModePrefix.enabled = prefs.ignoreModeEnabled;
fields.ddIgnoreModeSelection.selection = PrefixSelectionMode.getIndex(prefs.ignoreModeSelection);
fields.ddIgnoreModeSelection.enabled = prefs.ignoreModeEnabled;
fields.lblIgnoreModeSelection.enabled = prefs.ignoreModeEnabled;
fields.txtIgnoreModePrefix.text = prefs.ignoreModeString;

fields.cbIgnoreModeSelectionEnabled.onClick = function() {
fields.lblIgnoreModeSelection.enabled = this.value;
fields.txtIgnoreModePrefix.enabled = this.value;
fields.ddIgnoreModeSelection.enabled = this.value;
};


Expand Down Expand Up @@ -1564,8 +1594,9 @@ function saveSettings(dialog) {
desc.putInteger(DEFAULT_SETTINGS.exportLayerTarget, exportLayerTarget);
desc.putString(DEFAULT_SETTINGS.fileType, fields.tabpnlExportOptions.selection.text);
desc.putBoolean(DEFAULT_SETTINGS.groupsAsFolders, fields.cbGroupsAsFolders.value);
desc.putBoolean(DEFAULT_SETTINGS.ignoreLayers, fields.cbIgnorePrefix.value);
desc.putString(DEFAULT_SETTINGS.ignoreLayersString, fields.txtIgnorePrefix.text);
desc.putBoolean(DEFAULT_SETTINGS.ignoreModeEnabled, fields.cbIgnoreModeSelectionEnabled.value);
desc.putString(DEFAULT_SETTINGS.ignoreModeString, fields.txtIgnoreModePrefix.text);
desc.putInteger(DEFAULT_SETTINGS.ignoreModeSelection, PrefixSelectionMode.forIndex(fields.ddIgnoreModeSelection.selection.index));

desc.putInteger(DEFAULT_SETTINGS.jpgQuality, fields.sldrJpgQuality.value);
desc.putInteger(DEFAULT_SETTINGS.jpgMatte, fields.ddJpgMatte.selection.index);
Expand Down Expand Up @@ -1659,7 +1690,8 @@ function getDefaultSettings() {
exportLayerTarget: ExportLayerTarget.ALL_LAYERS,
fileType: "PNG-24",
groupsAsFolders: false,
ignoreLayersString: "!",
ignoreModeString: "!",
ignoreModeSelection: 0,
jpgIcc: false,
jpgMatte: 0,
jpgOptimized: false,
Expand Down Expand Up @@ -1741,8 +1773,9 @@ function getSettings(formatOpts) {
exportLayerTarget: desc.getInteger(DEFAULT_SETTINGS.exportLayerTarget),
fileType: desc.getString(DEFAULT_SETTINGS.fileType),
groupsAsFolders: desc.getBoolean(DEFAULT_SETTINGS.groupsAsFolders),
ignoreLayers: desc.getBoolean(DEFAULT_SETTINGS.ignoreLayers),
ignoreLayersString: desc.getString(DEFAULT_SETTINGS.ignoreLayersString),
ignoreModeEnabled: desc.getBoolean(DEFAULT_SETTINGS.ignoreModeEnabled),
ignoreModeString: desc.getString(DEFAULT_SETTINGS.ignoreModeString),
ignoreModeSelection: desc.getInteger(DEFAULT_SETTINGS.ignoreModeSelection),
jpgIcc: desc.getBoolean(DEFAULT_SETTINGS.jpgIcc),
jpgMatte: desc.getInteger(DEFAULT_SETTINGS.jpgMatte),
jpgOptimized: desc.getBoolean(DEFAULT_SETTINGS.jpgOptimized),
Expand Down Expand Up @@ -2469,8 +2502,10 @@ function getDialogFields(dialog) {
radioAll: dialog.findElement("radioAll"),
radioSelected: dialog.findElement("radioSelected"),
cbVisibleOnly: dialog.findElement("cbVisibleOnly"),
cbIgnorePrefix: dialog.findElement("cbIgnorePrefix"),
txtIgnorePrefix: dialog.findElement("txtIgnorePrefix"),
cbIgnoreModeSelectionEnabled: dialog.findElement("cbIgnoreModeSelectionEnabled"),
txtIgnoreModePrefix: dialog.findElement("txtIgnoreModePrefix"),
ddIgnoreModeSelection: dialog.findElement("ddIgnoreModeSelection"),
lblIgnoreModeSelection: dialog.findElement("lblIgnoreModeSelection"),

ddNameAs: dialog.findElement("ddNameAs"),
cbDelimiter: dialog.findElement("cbDelimiter"),
Expand Down Expand Up @@ -2654,20 +2689,40 @@ function makeMainDialog() {

// GRPIGNOREPREFIX
// ===============
var grpIgnorePrefix = grpIgnore.add("group", undefined, {name: "grpIgnorePrefix"});
grpIgnorePrefix.orientation = "row";
grpIgnorePrefix.alignChildren = ["left","center"];
grpIgnorePrefix.spacing = 10;
grpIgnorePrefix.margins = 0;

var cbIgnorePrefix = grpIgnorePrefix.add("checkbox", undefined, undefined, {name: "cbIgnorePrefix"});
cbIgnorePrefix.helpTip = "Ignore layers starting with";
cbIgnorePrefix.text = "Ignore Layers Starting With ";

var txtIgnorePrefix = grpIgnorePrefix.add('edittext {properties: {name: "txtIgnorePrefix"}}');
txtIgnorePrefix.helpTip = "The prefix to match against";
txtIgnorePrefix.text = "!";
txtIgnorePrefix.preferredSize.width = 31;
var grpIgnoreModePrefix = grpIgnore.add("group", undefined, {name: "grpIgnorePrefix"});
grpIgnoreModePrefix.orientation = "row";
grpIgnoreModePrefix.alignChildren = ["left","center"];
grpIgnoreModePrefix.spacing = 10;
grpIgnoreModePrefix.margins = 0;

var cbIgnoreModeSelectionEnabled = grpIgnoreModePrefix.add("checkbox", undefined, undefined, {name: "cbIgnoreModeSelectionEnabled"});
cbIgnoreModeSelectionEnabled.helpTip = "Enable layer selection by prefix";
cbIgnoreModeSelectionEnabled.text = "";
var ddIgnoreModeSelection_array = ['Ignore', 'Only'];
var ddIgnoreModeSelection = grpIgnoreModePrefix.add(
'dropdownlist',
undefined,
undefined,
{
name: 'ddIgnoreModeSelection',
items: ddIgnoreModeSelection_array,
}
);
ddIgnoreModeSelection.helpTip = 'Choose whether to ignore or select only layers with prefix';
ddIgnoreModeSelection.selection = 0;

var lblIgnoreModeSelection = grpIgnoreModePrefix.add(
'statictext',
undefined,
undefined,
{ name: 'lblIgnoreModeSelection' }
);
lblIgnoreModeSelection.text = 'Layers Starting With';

var txtIgnoreModePrefix = grpIgnoreModePrefix.add('edittext {properties: {name: "txtIgnoreModePrefix"}}');
txtIgnoreModePrefix.helpTip = "The prefix to match against";
txtIgnoreModePrefix.text = "!";
txtIgnoreModePrefix.preferredSize.width = 31;

// PNLNAMEFILES
// ============
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ This script does not try to achieve feature parity with the built-in script, but
- [Contributing](#contributing)
- [Feedback / Bugs](#feedback--bugs)


## How to Use

_Disclaimer:_ We are not associated with Adobe in any way. For any issues relating to Adobe products or Adobe scripts please contact them directly. We have never had an issue, but **please use this script at your own risk**. We are not responsible for any lost data or damaged PSDs so always make a back-up.
Expand Down Expand Up @@ -58,11 +57,11 @@ Some of the features of the script include...

Will only export the selected group. Note that you must selected the group before launching the script, otherwise this option will be disabled. When you run the script this way, all other layers will be left untouched, meaning any visible layers on top or bottom may show in the export.

### Ignore Layers Starting With
### Ignore/Only Layers Starting With

When this is selected, you can specify a prefix that will be used to match against layer names. Any matching layers will be ignored during the export.
When this is selected, you can specify whether to ignore or select layers with a specified prefix. Depending on the option selected only layers with prefix or without it will be exported.

For example, if you specify `x` in the input, all layers starting with the letter `x` will not be exported.
For example, if you specify `x` in the input when 'Ignore' mode is selected, all layers starting with the letter `x` will not be exported. If you select 'Only' mode, just the layers with name starting witx `x` will be exported.

### Filenames

Expand Down Expand Up @@ -140,7 +139,6 @@ To use the script this way, follow these instructions:

In order to make changes to the settings again, you'll need to change `BATCH_OPERATION` back to `false` and rerun the script.


## Requirements

We do our best to have the script be backwards compatible (back to Adobe Photoshop CS2) but are limited in what we can test for, both by Photoshop versions as well as OS. If you are encountering any issues with the current version, try downloading [previous versions](https://github.com/antipalindrome/Photoshop-Export-Layers-to-Files-Fast/releases) of the script instead.
Expand Down
2 changes: 1 addition & 1 deletion dev/dialog.js

Large diffs are not rendered by default.

Loading