Created
April 1, 2015 15:56
-
-
Save caiodv/74f77f0ef64d193b4adc to your computer and use it in GitHub Desktop.
Saves all Illustrator paths points in a document to json.
This file contains hidden or 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
main(); | |
function main(){ | |
var doc = app.activeDocument; | |
jsonText = '{"paths":[' | |
for(var i=0;i<doc.pathItems.length;i++){ | |
var _path = doc.pathItems[i]; | |
var _points = _path.pathPoints; | |
jsonText += '{"points":[' | |
for (var j = 0; j < _points.length; j++) { | |
jsonText += '{"x":'+_points[j].anchor[0]+',"y":'+_points[j].anchor[1]+'}' | |
if(j != _points.length - 1){ | |
jsonText += ',' | |
} | |
} | |
jsonText += ']}' | |
if(i != doc.pathItems.length - 1){ | |
jsonText += ',' | |
} | |
} | |
jsonText += ']}' | |
var name = decodeURI(doc.name); | |
name = name.substring(0, name.indexOf(".")); | |
var file = new File(doc.path.toString() + "/" + name + ".json"); | |
file.remove(); | |
file.open("w", "TEXT"); | |
file.lineFeed = "\n"; | |
file.write(jsonText); | |
file.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment