Skip to main content
whiskys8043558
Participant
March 12, 2018
Answered

Help with an incrementation and exporting script.

  • March 12, 2018
  • 1 reply
  • 863 views

Hi, I'm trying to use the following code to increment a text layer then export the image. It successfully increments, but it's not exporting or throwing an error message. Note: Most of this code isn't mine, and I'm a relative newb.

----------------------------------------------------

var layer = activeDocument.layers[0];

if (layer.kind == 'LayerKind.TEXT') {

for (var i=1; i < 7; i++) {

layer.textItem.contents = i.toString();

sfwPNG24('C:\Users\WS\Pictures\ ' + i + '.png');

}

}

function sfwPNG24(saveFile){

var pngOpts = new ExportOptionsSaveForWeb();

pngOpts.format = SaveDocumentType.PNG;

pngOpts.PNG8 = false;

pngOpts.transparency = true;

pngOpts.interlaced = false;

pngOpts.quality = 100;

activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);

}

This topic has been closed for replies.
Correct answer Tom Winkelmann

var layer = activeDocument.layers[0];

if (layer.kind == 'LayerKind.TEXT') {

for (var i=1; i < 7; i++) {

layer.textItem.contents = i.toString();

var saveFile = File('/C/Users/WS/Pictures/' + i + '.png');

sfwPNG24(saveFile);

}

};

function sfwPNG24(saveFile){

var pngOpts = new ExportOptionsSaveForWeb();

pngOpts.format = SaveDocumentType.PNG;

pngOpts.PNG8 = false;

pngOpts.transparency = true;

pngOpts.interlaced = false;

pngOpts.quality = 100;

activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);

}

This should work.

1 reply

Tom Winkelmann
Tom WinkelmannCorrect answer
Inspiring
March 12, 2018

var layer = activeDocument.layers[0];

if (layer.kind == 'LayerKind.TEXT') {

for (var i=1; i < 7; i++) {

layer.textItem.contents = i.toString();

var saveFile = File('/C/Users/WS/Pictures/' + i + '.png');

sfwPNG24(saveFile);

}

};

function sfwPNG24(saveFile){

var pngOpts = new ExportOptionsSaveForWeb();

pngOpts.format = SaveDocumentType.PNG;

pngOpts.PNG8 = false;

pngOpts.transparency = true;

pngOpts.interlaced = false;

pngOpts.quality = 100;

activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);

}

This should work.

whiskys8043558
Participant
March 12, 2018

Thanks, works like a charm.