I am working with a set of 28 *.tif image files organized as layers in a .psd file. My goal is to replace each layer with a different .tif file using a script (jsx) with a loop structure like this:
for (i=1;i<=28;i++) {
for j in (start,end) {
for k in (a,b,c,d,e,f) {
file = 'chr' + $i + '_' + $j + '_' + $k;
}}}
Update July 2020: After some time, I managed to find a solution which involves downloading json2.js and implementing it into the code snippet below:
// Replace smart object content and save psd;
#target photoshop
#include json2.js
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
psdOpts.layers = true;
psdOpts.spotColors = true;
// Lists for desired filename input
var ppath = "c:/here/goes/file/path/for/taking/input/file";
// (You can implement using JSON too)
var num = [
"2",
"3",
...
];
...
...
// Main code implementation begins here:
for (var i in num) {
saveJPEG(thNamer);
alert("saved Jpeg");
myDocument.saveAs((new File("D:\\thesis-bioinformatics" + '/vol-ID/' + thNamer + "_" +".psd")),psdOpts,true);
alert("saved PSD");
for (var k in letter) {
var TitleGroup = myDocument.layerSets.getByName('chr_place_plot_');
...
}
}
};