-
-
Save savage69kr/9976099 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 | |
/*-------------------------------------------------------- | |
Config | |
-------------------------------------------------------*/ | |
var originalRulerUnits = preferences.rulerUnits; | |
preferences.rulerUnits = Units.PIXELS; | |
/*-------------------------------------------------------- | |
Functions | |
-------------------------------------------------------*/ | |
function doCheck() { | |
if(!documents.length) { | |
alert('There are no documents open.'); | |
return; | |
} | |
} | |
function traverseLayer(doc) { | |
var layers = doc.layers; | |
// not very efficient for multilevel layers | |
for(var i = 0; i < layers.length; i++) { | |
// if group | |
if(layers[i].typename == "LayerSet") { | |
var name = layers[i].name; | |
// filter by group name | |
if(name.indexOf("@") > 0) { | |
for(var j = 0; j < layers[i].layers.length; j++) { | |
getLayerAttribute(layers[i].layers[j], name); | |
} | |
} | |
} | |
} | |
} | |
function getLayerAttribute(layer, name) { | |
// write down the attributes to XML | |
var s = "\t<pos name=\"" + name.substring(0, name.length - 1) + ".png\" x=\"" + layer.bounds[0].value + "\" y=\"" + layer.bounds[1].value + "\"></pos>\n"; | |
str += s.toString(); | |
} | |
/*-------------------------------------------------------- | |
Start | |
--------------------------------------------------------*/ | |
var doc = app.activeDocument; | |
var docWidth = doc.width.value; | |
var docHeight = doc.height.value; | |
var docFilePath = doc.fullName.path + "/"; | |
var docFileName = doc.name.match(/([^\.]+)/)[1]; | |
var docXMLName = docFilePath.toString().match(/([^\.]+)/)[1] + docFileName + ".xml"; | |
var str = "<item btn=\"btn" + docFileName +".png\" cover=\""+ docFileName + ".png\">\n"; | |
doCheck(); | |
traverseLayer (doc); | |
// create a reference to a file for output | |
var csvFile = new File(docXMLName); | |
// open the file, write the data, then close the file | |
csvFile.open('w'); | |
csvFile.writeln(str + "</item>"); | |
csvFile.close(); | |
preferences.rulerUnits = originalRulerUnits; | |
// Confirm that operation has completed | |
alert("XML Complete!""\n" + docXMLName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment