Export Layer Coordinates – Adobe Photoshop Script
Export x and y coordinates to semicolon seperated .txt file
//Adobe Photoshop 2022 var doc = app.activeDocument; var curLayer; var coordArray = []; var txtFile=""; var outName = "PSD_Coordinates"; goThroughLayers (doc); //Looping Array Elements for (i = 0; i < coordArray.length; i++) { txtFile += coordArray[i][0] + ";" + coordArray[i][1] + "\n"; } //Ask the user for the folder to export to var FPath = Folder.selectDialog("Save exported coordinates to"); //Detect line feed type if ( $.os.search(/windows/i) !== -1 ) { fileLineFeed = "Windows"; } else { fileLineFeed = "Macintosh"; } //Export to txt file writeFile(txtFile); function writeFile(info) { try { var f = new File(FPath + "/" + outName + ".txt"); f.remove(); f.open('a'); f.lineFeed = fileLineFeed; f.write(info); f.close(); } catch(e){} } //Recursive function to go through each layer function goThroughLayers(parentLayer){ for(var i=0;i<parentLayer.layers.length;i++){ curLayer = parentLayer.layers[i]; doc.activeLayer = curLayer; if(curLayer.typename =='LayerSet'){goThroughLayers (curLayer)} else{ if(curLayer.kind = LayerKind.NORMAL){ var layerBounds = curLayer.bounds; coordArray.push([layerBounds[0].value,layerBounds[1].value]); } } } }
//Adobe Photoshop CC var doc = app.activeDocument; //go through each layer and create a folder //alert('length is ' + doc.artLayers.length); var length = doc.artLayers.length; var coordArray = []; var txtFile=""; for (var layer = 0; layer < length; layer++) { // get the layer bounds var layerBounds = doc.artLayers[layer].bounds; // get top left position coordArray.push([layerBounds[0].value,layerBounds[1].value]); } //Looping Array Elements //for (var i = coordArray.length - 1; i >= 0; --i) for (i = 0; i < coordArray.length; i++) { txtFile += coordArray[i][0] + ";" + coordArray[i][1] + "\n"; } var outName = "PSD_Coordinates.txt"; var outFile = new File( "<your folder full path>" + outName ); outFile.open( "w" ); outFile.write(txtFile); outFile.close();