Last active
September 17, 2016 22:12
-
-
Save marianomike/98115bad1c9ffa30df39e8de153bbed1 to your computer and use it in GitHub Desktop.
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
function exportJSON(layer, file_path){ | |
//initialize the layer array | |
var layerArray = []; | |
//create the variables | |
var layerName = String(layer.name()); | |
var layerFrame = layer.absoluteRect(); | |
var layerXpos = String(layerFrame.x()); | |
var layerYpos = String(layerFrame.y()); | |
var layerHeight = String(layerFrame.height()); | |
var layerWidth = String(layerFrame.width()); | |
// add the strings to the array | |
layerArray.push({ | |
name: layerName, | |
xPos: layerXpos, | |
yPos: layerYpos, | |
height: layerHeight, | |
width: layerWidth, | |
}); | |
// Create the JSON object from the layer array | |
var jsonObj = { "layer": layerArray }; | |
// Convert the object to a json string | |
var file = NSString.stringWithString(JSON.stringify(jsonObj, null, "\t")); | |
// Save the file | |
[file writeToFile:file_path+layerName+".json" atomically:true encoding:NSUTF8StringEncoding error:null]; | |
var alertMessage = layerName+".json saved to: " + file_path; | |
alert("Layer JSON Exported!", alertMessage); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment