Created
January 6, 2014 14:18
-
-
Save lorddarq/8283444 to your computer and use it in GitHub Desktop.
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
#target Photoshop | |
//Initialize Photoshop & choose what file is processed | |
app.bringToFront(); | |
var filepath = File.openDialog (); | |
var fileRef = File(filepath); | |
var docRef = app.open(fileRef); | |
//required Variables | |
var i=0; | |
var sampledColors = new Array(); | |
var layerCompStack = new Array(); | |
var compNames = new Array(); | |
//define a function that takes care of exporting found colors automatically; | |
var getLayerComps = function(){ | |
var index=0; | |
var comps = app.activeDocument.layerComps.length; | |
var layerCompRef; | |
//create the export folders | |
var exportiOSFolder = new Folder(Folder.desktop + "/export/iOS/"); | |
if(!exportiOSFolder.exists) exportiOSFolder.create(); | |
var exportAndroidFolder = new Folder(Folder.desktop + "/export/Android/"); | |
if(!exportAndroidFolder.exists) exportAndroidFolder.create(); | |
// add all comps you found into an array to be used as indexes later. | |
for(i=0;i<comps;i++){ | |
layerCompStack[i] = i; | |
}; | |
//use the indexes found to get all layercomp names and store them in a new array. | |
for(index = 0;index <layerCompStack.length;index++){ | |
compNames[layerCompStack[index]] = app.activeDocument.layerComps[layerCompStack[index]].name; | |
}; | |
//iterate through all layercomps and for each apply the the comp, create a new object with set properties and assign some color values to those properties | |
//then, export the layercomps into a text file that has a css-similar structure, based on nodes/trees. | |
//create the export file. | |
var exportiOS = new File(Folder.desktop + "/export/iOS/" + "backgrounds" + ".node"); | |
var exportAndroid = new File(Folder.desktop + "/export/Android/" + "backgrounds" + ".node"); | |
//clear the UI node file each time before writing to it. | |
exportiOS.open("w", "TEXT"); | |
exportAndroid.open("w","TEXT"); | |
exportiOS. write(""); | |
exportAndroid. write(""); | |
exportiOS.close(); | |
exportAndroid.close(); | |
// do the magic! | |
for (var key in compNames){ | |
var val = compNames[key]; | |
var layerCompRef = app.activeDocument.layerComps.getByName(val); | |
//apply the layer comp | |
layerCompRef.apply(); | |
//get the Stroke color first | |
var getStrokeColor = function(){ | |
var strokeColor = app.activeDocument.colorSamplers[0].color.rgb.hexValue; | |
return "#"+strokeColor; | |
}; | |
//get the fill color next | |
var getFillColor = function(){ | |
var fillColor = app.activeDocument.colorSamplers[1].color.rgb.hexValue; | |
return "#"+fillColor; | |
}; | |
//create an object based on the properties found that uses the names stored in the compNames array | |
val = { | |
name: val, | |
stroke_color: getStrokeColor(), | |
fill_color: getFillColor(), | |
}; | |
//export all the information into a file called ui.node | |
exportiOS.open("a", "TEXT"); | |
exportiOS.writeln("<nodeName: "+val.name+"; "+"strokeColor: "+val.stroke_color+"; "+"fillColor: "+val.fill_color+";"+">"); | |
exportiOS.writeln(""); | |
exportiOS.close(); | |
}; | |
//Save the document and close it. We're being tidy. | |
app.activeDocument.save(); | |
app.activeDocument.close(); | |
//alert the user that the export process is completed! | |
return alert ("Exported! Give yourself a pat on the back for a job well done!", "Export"); | |
}; | |
getLayerComps (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment