Last active
September 12, 2015 00:37
-
-
Save niquedegraaff/9ca471e48bf04838d90e to your computer and use it in GitHub Desktop.
Photoshop Script for auto save (diffuse and alpha) png textures for Cities Skylines
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
#target photoshop | |
//////////////////////////////////////////////// | |
/// /// | |
/// P H O T O S H O P S C R I P T /// | |
/// ---------------------------------------- /// | |
/// PNG TEXTURE EXPORTS FOR CITIES SKYLINES /// | |
/// /// | |
/// Date: 9/12/2015 /// | |
/// Version: 1.1 /// | |
/// /// | |
/// This script saves the all the kinds of /// | |
/// texture maps with a (_x) suffix if the /// | |
/// art made for that texture map is placed /// | |
/// the corresponding group layer. /// | |
/// /// | |
/// It corrects the document's mode to rgb /// | |
/// 8 Bit and automaticly hides the /// | |
/// "Template" layer on save. It ignores the /// | |
/// "Background". The script only affects /// | |
/// root layers. /// | |
/// /// | |
/// You are free to use / change this script /// | |
/// But if you decide to redistribute please /// | |
/// mention my name as thanks for my effort. /// | |
/// /// | |
/// Update log: /// | |
/// v1.0: Support for diffuse and alpha /// | |
/// v1.1: Added support for all maps /// | |
/// /// | |
/// /// | |
/// Created by Nique de Graaff /// | |
/// /// | |
/// /// | |
/// [email protected] /// | |
/// /// | |
//////////////////////////////////////////////// | |
// Initialize | |
var doc = app.activeDocument; | |
var docName = doc.name.replace(/\.[^\.]+$/, ''); | |
var docExt = decodeURI(doc.name).replace(/^.*\./, ''); | |
var docPath = ""; | |
// Run the script | |
main(); | |
function main() | |
{ | |
// Check if the document exists | |
if (docExt.toLowerCase() != 'psd') return; | |
docPath = doc.path; | |
// Check if document is in RGB mode, if not update | |
if (doc.mode != DocumentMode.RGB) | |
{ | |
doc.changeMode(ChangeMode.RGB); | |
} | |
// Check if document is in 8 bit mode, if not update | |
if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) | |
{ | |
doc.bitsPerChannel = BitsPerChannelType.EIGHT; | |
} | |
// Make a list of all affected (root) layers | |
var affectedLayers = {}; | |
for (i = 0; i < doc.layers.length; i++) | |
{ | |
if (doc.layers[i].parent == doc) | |
affectedLayers[doc.layers[i].name] = doc.layers[i].visible; | |
} | |
// Save the diffuse texture | |
saveTexture('Diffuse'); | |
// Save the alpha texture | |
saveTexture('Alpha'); | |
// Save the color map texture | |
saveTexture('Color'); | |
// Save the illumination texture | |
saveTexture('Illumination'); | |
// Save the normal texture | |
saveTexture('Normal'); | |
// Save the specular texture | |
saveTexture('Specular'); | |
// Reset all layers as it was | |
for (var key in affectedLayers) | |
{ | |
if(affectedLayers.hasOwnProperty(key)) | |
{ | |
doc.layers.getByName(key).visible = affectedLayers[key]; | |
} | |
} | |
} | |
// Save Texture | |
function saveTexture(name) | |
{ | |
for(i = 0; i < doc.layers.length; i++) | |
{ | |
var currentLayer = doc.layers[i]; | |
var save = false; | |
var ext = ""; | |
if (currentLayer.name == name && currentLayer.parent == doc && currentLayer.name != 'Background') | |
{ | |
currentLayer.visible = true; | |
save = true; | |
ext = "_" + currentLayer.name.charAt(0).toLowerCase(); | |
} else { | |
currentLayer.visible = false; | |
save = false; | |
} | |
if (save == true) | |
{ | |
var file = File(docPath + "/" + docName + ext); | |
if (file.exists) file.remove(); | |
SavePNG(file); | |
} | |
} | |
} | |
// Saves the (texure) file to disk | |
function SavePNG(file) | |
{ | |
pngSaveOptions = new PNGSaveOptions(); | |
pngSaveOptions.compression = 0; | |
pngSaveOptions.interlaced = false; | |
activeDocument.saveAs(file, pngSaveOptions, true, Extension.LOWERCASE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install the script in Photoshop by adding it to the 'Save File' event in the Event Manager (under File -> Script). Disable when you do other work. Enable when you're texturing your models.