Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Photoshop extendscript javascript save to text file a list of layers

app.preferences.rulerUnits = Units.PIXELS;
var srcDoc = app.activeDocument;
var numOfLayers = srcDoc.layers.length;
var results = "";
var fileName = srcDoc.name;
var docName = fileName.substring(0,fileName.length -4)
var theFile = srcDoc.path + "/" + docName + ".txt";

for (var i = 0; i < numOfLayers  ; i++)
{
  var theLayer = srcDoc.layers[i];
  var lb = getLayerBounds(theLayer).toString();
  results += theLayer.name + ": " + lb + "
";
}

writeTextFile(theFile, results)
alert(results);

function getLayerBounds(alayer)
{
  var x1 = parseFloat(alayer.bounds[0])
  var y1 = parseFloat(alayer.bounds[1])
  var x2 = parseFloat(alayer.bounds[2])
  var y2 = parseFloat(alayer.bounds[3])
  return [x1,y1,x2,y2]
}

function writeTextFile(afilename, output)
{
  var txtFile = new File(afilename);
  txtFile.open("w"); //
  txtFile.writeln(output);
  txtFile.close();
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery put value in table 
Javascript :: bootstrap on tabs change 
Javascript :: remoteevent dont send object 
Javascript :: Could not resolve "i18n-iso-countries" 
Javascript :: How to get prime numbers using for loop in Js 
Javascript :: ngswitch example on string 
Javascript :: flip image on x axis phaser 
Javascript :: reactjs libphonenumber 
Javascript :: phaser place on line 
Javascript :: phaser add animation event 
Javascript :: phaser animation on stop event 
Javascript :: append input using js 
Javascript :: data tables ajust columns after init 
Javascript :: when end sound show alert 
Javascript :: 555 
Javascript :: membuat validasi form dengan javascript 
Javascript :: the document has mutated since the result was returned 
Javascript :: Slice and Splice -Javascript 2 
Javascript :: TypeError: expressValidator is not a function 
Javascript :: react router browser refresh 
Javascript :: codesandbox react emet 
Javascript :: what is closures in javascript 
Javascript :: values javascript 
Javascript :: react native 
Javascript :: age calculator moment js 
Javascript :: type conversion in javascript 
Javascript :: javascript exeit from loop 
Javascript :: scrollbar position 
Javascript :: append to array in js 
Javascript :: how to build a string javascript es6 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =