|
#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/" + "buttons" + ".node"); |
|
var exportAndroid = new File(Folder.desktop + "/export/Android/" + "buttons" + ".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 gradient start next |
|
var getGradientStartColor = function(){ |
|
var gradientStartColor = app.activeDocument.colorSamplers[1].color.rgb.hexValue; |
|
return "#"+gradientStartColor; |
|
}; |
|
|
|
//finally get the gradient stop |
|
var getGradientStopColor = function(){ |
|
var gradientStopColor = app.activeDocument.colorSamplers[2].color.rgb.hexValue; |
|
return "#"+gradientStopColor; |
|
}; |
|
|
|
//create an object based on the properties found that uses the names stored in the compNames array |
|
val = { |
|
name: val, |
|
stroke_color: getStrokeColor(), |
|
gradient_start_color: getGradientStartColor(), |
|
gradient_stop_color: getGradientStopColor() |
|
}; |
|
|
|
//export all the information into a file called ui.node |
|
exportiOS.open("a", "TEXT"); |
|
exportiOS.writeln("<nodeName: "+val.name+"; "+"strokeColor: "+val.stroke_color+"; "+"gradientStart: "+val.gradient_start_color+"; "+"gradientStop: "+val.gradient_stop_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 (); |