Photoshop script for exporting XML automatically

General discussion about ZunTzu in English.

Moderators: Ichibrothers, Cambronne

Post Reply
Heath
101
Posts: 56
Joined: 24 Jul 2010, 19:40
Location: USA

Photoshop script for exporting XML automatically

Post by Heath »

Here's a script you can use to export selection coordinates in Photoshop as a counter coordinate line for ZunTzu's game-box.xml:

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&#40;'<counter-section front-left="'+x.toFixed&#40;0&#41;+'" front-top="'+y.toFixed&#40;0&#41;+'" front-right="'+w.toFixed&#40;0&#41;+'" front-bottom="'+h.toFixed&#40;0&#41;+'" supply="1" />'&#41;;
&#125;catch&#40;e&#41;&#123;&#125;
file.close&#40;&#41;;
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:

Code: Select all

<counter-section front-left="257" front-top="347" front-right="361" front-bottom="343" supply="1" />
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
User avatar
Jerome
Site Admin
Posts: 974
Joined: 22 Jun 2006, 21:31
Location: France
Contact:

Post by Jerome »

Great idea! Thanks! :)
Jerome, ZunTzu developer.
Post Reply