Photoshop script for exporting XML automatically
Posted: 29 Feb 2012, 00:55
Here's a script you can use to export selection coordinates in Photoshop as a counter coordinate line for ZunTzu's game-box.xml:
Copy paste this code into "Export Coordinates.jsx", then add it to Photoshop's Presets/Scripts folder. It should now be listed under File / Scripts / Export Coordinates. A file called "Bounds Info.txt" will be created on your desktop, with information like this:
So now you can take an irregular sheet of counters, and just select them with the Rectangular Marquee tool, running this script after each selection. In this way, the XML is written for you. I hope you find this as useful as I did.
Heath
Code: Select all
var file = new File(Folder.desktop + "/Bounds Info.txt");
file.open("e", "TEXT", "????");
$.os.search(/windows/i) != -1 ? file.lineFeed = 'windows' : file.lineFeed = 'macintosh';
file.seek(0,2);
try{
var Name = decodeURI(activeDocument.name);
var b = app.activeDocument.selection.bounds;
var x = b[0].value;
var y = b[1].value;
var w = b[2].value-b[0].value + x;
var h = b[3].value-b[1].value + y;
var unit = b[0].type;
file.writeln('<counter-section front-left="'+x.toFixed(0)+'" front-top="'+y.toFixed(0)+'" front-right="'+w.toFixed(0)+'" front-bottom="'+h.toFixed(0)+'" supply="1" />');
}catch(e){}
file.close();
Code: Select all
<counter-section front-left="257" front-top="347" front-right="361" front-bottom="343" supply="1" />
Heath