Created
April 17, 2012 16:49
-
-
Save stevederico/2407431 to your computer and use it in GitHub Desktop.
LayerCake Rename Layers Photoshop Script
This file contains 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
//LayerCake Rename PhotoShop Script by Steve Derico http://www.stevederico.com | |
Credits: | |
// Rename Layers - Adobe Photoshop Script | |
// Requirements: Adobe Photoshop CS, or higher | |
// Description: renames and numbers all layers in the active document (using the supplied name pattern) | |
// Author: Trevor Morris (trevor@morris-photographics.com) | |
// Website: http://morris-photographics.com/ | |
// ============================================================================ | |
// Installation: | |
// 1. Place script in '/Applications/Photoshop/Presets/Scripts' | |
// 2. Restart Photoshop | |
// 3. Choose File > Scripts > Rename Layers | |
// ============================================================================ | |
/////////////////////////////////////////////////////////////////////////////// | |
// main - main function | |
/////////////////////////////////////////////////////////////////////////////// | |
function main() { | |
// user settings | |
var prefs = new Object(); | |
prefs.countFrom = 1; // number to start counting from (default: 1) | |
prefs.zeroPadding = 3; // number of digits to use for the layer number (defaul: 3) | |
prefs.nameSeparator = ' '; // character to insert between the layer name and number (default: ' ') | |
prefs.topToBottom = false; // rename layers top to bottom (true) or bottom to top (false) | |
// rename layers | |
renameLayers(activeDocument, prefs); | |
} | |
/////////////////////////////////////////////////////////////////////////////// | |
// renameLayers - rename layers, top to bottom, or bottom to top | |
/////////////////////////////////////////////////////////////////////////////// | |
function renameLayers(ref, prefs) { | |
// declare local variables | |
var len = ref.layers.length; | |
// rename layers top to bottom | |
if (prefs.topToBottom) { | |
for (var i = 0; i < len; i++) { | |
rename(); | |
} | |
} | |
// rename layers bottom to top | |
else { | |
for (var i = len - 1; i >= 0; i--) { | |
rename(); | |
} | |
} | |
// rename - rename layer | |
function rename() { | |
var layer = ref.layers[i]; | |
var vis = layer.visible; | |
var txt = ".png"; | |
// check for groups | |
if (layer.typename == 'LayerSet') { | |
renameLayers(layer, prefs); | |
} | |
// rename layer | |
else { | |
layer.name = layer.name.concat(txt); | |
if (!vis) { | |
layer.visible = false; | |
} | |
prefs.countFrom++; | |
} | |
} | |
} | |
/////////////////////////////////////////////////////////////////////////////// | |
// isCorrectVersion - check for Adobe Photoshop CS (v8) or higher | |
/////////////////////////////////////////////////////////////////////////////// | |
function isCorrectVersion() { | |
if (parseInt(version, 10) >= 8) { | |
return true; | |
} | |
else { | |
alert('This script requires Adobe Photoshop CS or higher.', 'Wrong Version', false); | |
return false; | |
} | |
} | |
/////////////////////////////////////////////////////////////////////////////// | |
// isOpenDocs - ensure at least one document is open | |
/////////////////////////////////////////////////////////////////////////////// | |
function isOpenDocs() { | |
if (documents.length) { | |
return true; | |
} | |
else { | |
alert('There are no documents open.', 'No Documents Open', false); | |
return false; | |
} | |
} | |
/////////////////////////////////////////////////////////////////////////////// | |
// showError - display error message if something goes wrong | |
/////////////////////////////////////////////////////////////////////////////// | |
function showError(err) { | |
if (confirm('An unknown error has occurred.\n' + | |
'Would you like to see more information?', true, 'Unknown Error')) { | |
alert(err + ': on line ' + err.line, 'Script Error', true); | |
} | |
} | |
/////////////////////////////////////////////////////////////////////////////// | |
// test initial conditions prior to running main function | |
/////////////////////////////////////////////////////////////////////////////// | |
if (isCorrectVersion() && isOpenDocs()) { | |
try { | |
main(); | |
} | |
catch(e) { | |
if (e.number != 8007) { // don't report error on user cancel | |
showError(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment