我是javascript的新手,我正在尝试编写一个脚本,用于从csv文件中读取数据的photoshop。 photoshop文件有各种文本层,从csv提供数据。我无法为完成的每个csv行关闭图像层。关于如何写这个的任何想法?
以下是目前的代码:
var data = [];
var dataFile = new File(app.activeDocument.path + '/data.csv');
dataFile.open('r');
dataFile.readln(); // Skip first line
while (!dataFile.eof) {
var dataFileLine = dataFile.readln();
var dataFilePieces = dataFileLine.split(',');
data.push({
art: dataFilePieces[0],
tileNumber: dataFilePieces[0],
tileCommon: dataFilePieces[1],
tileSpecies: dataFilePieces[2],
tileDescription: dataFilePieces[3],
tileStatus: dataFilePieces[4],
});
}
dataFile.close();
for (var tileIndex = 0; tileIndex < data.length; tileIndex++) {
var tileData = data[tileIndex];
//update number
app.activeDocument.artLayers.getByName('Tile number').textItem.contents = tileData.tileNumber;
//update common name
app.activeDocument.artLayers.getByName('Common name').textItem.contents = tileData.tileCommon;
//update species name
app.activeDocument.artLayers.getByName('Species name').textItem.contents = tileData.tileSpecies;
//update description
app.activeDocument.artLayers.getByName('Description').textItem.contents = tileData.tileDescription;
file = new File(app.activeDocument.path + '/' + tileData.tileCommon + '.png');
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.PNG;
opts.PNG8 = false;
opts.quality = 100;
app.activeDocument.exportDocument(file, ExportType.SAVEFORWEB, opts);
}
confirm("All done!");