So I have these 28 *.tif image files as 28 layers (smart objects) I have arranged in a .psd file and wish to replace each layer with another .tif file. I wish to run some script(jsx) with loop something 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 July2020: sorry for this late, I had found one solution and was like this, you first should download json2.js :
// replace smart object’s 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",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"X",
"Y"
];
var nnum = [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"X"
];
var lletter = [
"q",
"p",
"o",
"n",
"m",
"l",
"u",
"t",
"k",
"j",
"i",
"h",
"g",
"f",
"d",
"c",
"b",
"ae",
"ad",
"ac",
"ab",
"aa",
"a",
"z",
"y",
"x",
"w",
"v"
];
var letter = [
"q",
"p",
"o",
"n",
"m",
"l",
"u",
"t",
"k",
"j",
"i",
"h",
"g",
"f",
"d",
"c",
"b",
"ae",
"ad",
"ac",
"ab",
"aa",
"a",
"z",
"y",
"x",
"w",
"v"
];
// main code starts 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_');
var TitleGroup2 = myDocument.layerSets.getByName('chr_text');
var thNamer = 'chr' + num[i] + '_start' + '_plot_';
var thNames = 'chr' + num[i] + '_start' + '_plot_' + letter[k];
var thprevNames = 'chr' + nnum[i] + '_start' + '_plot_' + letter[k];
VolLayer = TitleGroup.artLayers.getByName(thprevNames);
VolLayer2 = TitleGroup2.artLayers.getByName('Chr1');
myDocument.activeLayer = VolLayer;
var theFiles = ppath + thNames + '.tif';
if (theFiles && thprevNames != thNames)
{
VolLayer = replaceContents(theFiles);
VolLayer2.textItem.contents = thNamer;
}
}
}
};
2
Answers
This will take input in JSON and replace text and similarly can be made to replace images giving the file path.
What it does is simply look for the layer group and then replace the content with the text or the file of your choice then save the jpg and PSD file in an output folder.
You can see the code here: https://github.com/avialxee/photoshop-jsx
Try This Code
It’ll loop through all layers and will replace it with the .tiff file you’ll choose